class StandupMD::Cli
Class for handing the command-line interface.
Attributes
entry[R]
The entry searched for, usually today.
@return [StandupMD::Entry]
file[R]
The file loaded.
@return [StandupMD::File]
options[R]
Arguments passed at runtime.
@return [Array] ARGV
Public Class Methods
config()
click to toggle source
Access to the class's configuration.
@return [StandupMD::Config::Cli]
# File lib/standup_md/cli.rb, line 16 def self.config @config ||= StandupMD.config.cli end
echo(msg)
click to toggle source
Prints output if verbose
is true.
@return [nil]
# File lib/standup_md/cli.rb, line 24 def self.echo(msg) puts msg if config.verbose end
execute(options = [])
click to toggle source
Creates an instance of StandupMD
and runs what the user requested.
# File lib/standup_md/cli.rb, line 30 def self.execute(options = []) new(options).tap do |exe| exe.write_file if config.write if config.print exe.print(exe.entry) elsif config.edit exe.edit end end end
new(options = [], load_config = true)
click to toggle source
Constructor. Sets defaults.
@param [Array] options
# File lib/standup_md/cli.rb, line 63 def initialize(options = [], load_config = true) @config = self.class.config @preference_file_loaded = false @options = options load_preferences if load_config load_runtime_preferences(options) @file = StandupMD::File.find_by_date(@config.date) @file.load @entry = new_entry(@file) end
Public Instance Methods
echo(msg)
click to toggle source
Quick access to Cli.echo
.
@return [nil]
# File lib/standup_md/cli.rb, line 117 def echo(msg) self.class.echo(msg) end
edit()
click to toggle source
Opens the file in an editor. Abandons the script.
@return [nil]
# File lib/standup_md/cli.rb, line 99 def edit echo "Opening file in #{@config.editor}" exec("#{@config.editor} #{file.name}") end
load_preferences()
click to toggle source
Load the preference file.
@return [nil]
# File lib/standup_md/cli.rb, line 78 def load_preferences if ::File.exist?(@config.preference_file) ::StandupMD.load_config_file(@config.preference_file) @preference_file_loaded = true else echo "Preference file #{@config.preference_file} does not exist." end end
preference_file_loaded?()
click to toggle source
Has the preference file been loaded?
@return boolean
# File lib/standup_md/cli.rb, line 91 def preference_file_loaded? @preference_file_loaded end
write_file()
click to toggle source
Writes entries to the file.
@return [Boolean] true if file was written
# File lib/standup_md/cli.rb, line 108 def write_file echo "Writing file #{file.name}" file.write end