class StandupMD::Cli
Class for handling the command-line interface.
Constants
- ZSH_COMPLETION_FILE
-
Path to the bundled zsh completion script.
@return [String]
Attributes
Runtime configuration snapshot for this CLI invocation.
@return [StandupMD::Config]
The entry searched for, usually today.
@return [StandupMD::Entry]
The file loaded.
@return [StandupMD::File]
Arguments passed at runtime.
@return [Array] ARGV
Public Class Methods
Source
# File lib/standup_md/cli.rb, line 24 def self.config StandupMD.config.cli end
Access to the classβs configuration.
@return [StandupMD::Config::Cli]
Source
# File lib/standup_md/cli.rb, line 32 def self.echo(msg) puts msg if config.verbose end
Prints output if verbose is true.
@return [nil]
Source
# File lib/standup_md/cli.rb, line 68 def self.execute(options = []) new(options).tap do |exe| if exe.zsh_completion_requested? puts zsh_completion_instructions next end exe.write_file if exe.write? if exe.config.cli.print exe.print(exe.entry) elsif exe.config.cli.post exe.post(exe.entry) elsif exe.config.cli.edit exe.edit end end end
Creates an instance of StandupMD and runs what the user requested.
Source
# File lib/standup_md/cli.rb, line 130 def initialize(options = [], load_config: true) @config = nil @preference_file_loaded = false @file_date_argument = false @current_option_passed = false @zsh_completion_requested = false @options = options return if load_zsh_completion_request(options) load_preferences if load_config @config = StandupMD.config.copy load_runtime_preferences(options) return if zsh_completion_requested? @file = find_file @file&.load @entry = @file.nil? ? nil : new_entry(@file) end
Constructor. Sets defaults.
@param [Array] options
Source
# File lib/standup_md/cli.rb, line 40 def self.zsh_completion_instructions completion_dir = ::File.dirname(ZSH_COMPLETION_FILE) <<~INSTRUCTIONS Zsh completion file: #{ZSH_COMPLETION_FILE} To load it directly, add this before compinit runs: fpath=("#{completion_dir}" $fpath) autoload -Uz compinit compinit Or symlink it into your own completion directory: mkdir -p ~/.zsh/completions ln -sf "#{ZSH_COMPLETION_FILE}" ~/.zsh/completions/_standup Then make sure that directory is in fpath before compinit runs: fpath=(~/.zsh/completions $fpath) autoload -Uz compinit compinit INSTRUCTIONS end
Prints zsh completion setup instructions.
@return [String]
Public Instance Methods
Source
# File lib/standup_md/cli.rb, line 209 def echo(msg) puts msg if @config&.cli&.verbose end
Quick access to Cli.echo.
@return [nil]
Source
# File lib/standup_md/cli.rb, line 175 def edit echo "Opening file in #{@config.cli.editor}" exec("#{@config.cli.editor} #{file.name}") end
Opens the file in an editor. Abandons the script.
@return [nil]
Source
# File lib/standup_md/cli.rb, line 114 def file_date_argument? @file_date_argument end
Was a file date argument passed?
@return [Boolean]
Source
# File lib/standup_md/cli.rb, line 153 def load_preferences preference_file = StandupMD.config.cli.preference_file if ::File.exist?(preference_file) ::StandupMD.load_config_file(preference_file) @preference_file_loaded = true else self.class.echo "Preference file #{preference_file} does not exist." end end
Load the preference file.
@return [nil]
Source
# File lib/standup_md/cli.rb, line 201 def post? @config.cli.post end
Should the CLI post the entry to a chat adapter?
@return [Boolean]
Source
# File lib/standup_md/cli.rb, line 167 def preference_file_loaded? @preference_file_loaded end
Has the preference file been loaded?
@return [boolean]
Source
# File lib/standup_md/cli.rb, line 193 def write? !!(@config.cli.write && !read_only? && entry) end
Should the file be written?
@return [Boolean]
Source
# File lib/standup_md/cli.rb, line 184 def write_file echo "Writing file #{file.name}" file.write end
Writes entries to the file.
@return [Boolean] true if file was written
Source
# File lib/standup_md/cli.rb, line 122 def zsh_completion_requested? @zsh_completion_requested end
Was zsh completion output requested?
@return [Boolean]