Class: StandupMD::Cli
- Inherits:
-
Object
- Object
- StandupMD::Cli
- Includes:
- Helpers
- Defined in:
- lib/standup_md/cli.rb,
lib/standup_md/cli/helpers.rb
Overview
Class for handing the command-line interface.
Defined Under Namespace
Modules: Helpers
Instance Attribute Summary collapse
-
#entry ⇒ StandupMD::Entry
readonly
The entry searched for, usually today.
-
#file ⇒ StandupMD::File
readonly
The file loaded.
-
#options ⇒ Array
readonly
Arguments passed at runtime.
Class Method Summary collapse
-
.config ⇒ StandupMD::Config::Cli
Access to the class’s configuration.
-
.echo(msg) ⇒ nil
Prints output if
verboseis true. -
.execute(options = []) ⇒ Object
Creates an instance of
StandupMDand runs what the user requested.
Instance Method Summary collapse
-
#echo(msg) ⇒ nil
Quick access to
Cli.echo. -
#edit ⇒ nil
Opens the file in an editor.
-
#initialize(options = [], load_config: true) ⇒ Cli
constructor
Constructor.
-
#load_preferences ⇒ nil
Load the preference file.
-
#preference_file_loaded? ⇒ boolean
Has the preference file been loaded?.
-
#write_file ⇒ Boolean
Writes entries to the file.
Methods included from Helpers
Constructor Details
#initialize(options = [], load_config: true) ⇒ Cli
Constructor. Sets defaults.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/standup_md/cli.rb', line 63 def initialize( = [], load_config: true) @config = self.class.config @preference_file_loaded = false @options = load_preferences if load_config load_runtime_preferences() @file = StandupMD::File.find_by_date(@config.date) @file.load @entry = new_entry(@file) end |
Instance Attribute Details
#entry ⇒ StandupMD::Entry (readonly)
The entry searched for, usually today.
45 46 47 |
# File 'lib/standup_md/cli.rb', line 45 def entry @entry end |
#file ⇒ StandupMD::File (readonly)
The file loaded.
57 58 59 |
# File 'lib/standup_md/cli.rb', line 57 def file @file end |
#options ⇒ Array (readonly)
Arguments passed at runtime.
51 52 53 |
# File 'lib/standup_md/cli.rb', line 51 def @options end |
Class Method Details
.config ⇒ StandupMD::Config::Cli
Access to the class’s configuration.
16 17 18 |
# File 'lib/standup_md/cli.rb', line 16 def self.config @config ||= StandupMD.config.cli end |
.echo(msg) ⇒ nil
Prints output if verbose is true.
24 25 26 |
# File 'lib/standup_md/cli.rb', line 24 def self.echo(msg) puts msg if config.verbose end |
.execute(options = []) ⇒ Object
Creates an instance of StandupMD and runs what the user requested.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/standup_md/cli.rb', line 30 def self.execute( = []) new().tap do |exe| exe.write_file if config.write if config.print exe.print(exe.entry) elsif config.edit exe.edit end end end |
Instance Method Details
#echo(msg) ⇒ nil
Quick access to Cli.echo.
117 118 119 |
# File 'lib/standup_md/cli.rb', line 117 def echo(msg) self.class.echo(msg) end |
#edit ⇒ nil
Opens the file in an editor. Abandons the script.
99 100 101 102 |
# File 'lib/standup_md/cli.rb', line 99 def edit echo "Opening file in #{@config.editor}" exec("#{@config.editor} #{file.name}") end |
#load_preferences ⇒ nil
Load the preference file.
78 79 80 81 82 83 84 85 |
# 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? ⇒ boolean
Has the preference file been loaded?
91 92 93 |
# File 'lib/standup_md/cli.rb', line 91 def preference_file_loaded? @preference_file_loaded end |
#write_file ⇒ Boolean
Writes entries to the file.
108 109 110 111 |
# File 'lib/standup_md/cli.rb', line 108 def write_file echo "Writing file #{file.name}" file.write end |