class StandupMD::CLI

Class for handing the command-line interface.

Constants

PREFERENCE_FILE

The user's preference file.

Attributes

options[R]

Arguments passed at runtime.

@return [Array] ARGV

preferences[R]

Preferences after reading config file and parsing ARGV.

@return [Array] ARGV

Public Class Methods

execute(options = []) click to toggle source

Creates an instance of StandupMD and runs what the user requested.

# File lib/standup_md/cli.rb, line 18
def self.execute(options = [])
  exe = new(options)
  exe.append_to_previous_entry_tasks if exe.should_append?

  exe.print_current_entry if exe.print_current_entry?
  exe.print_all_entries   if exe.print_all_entries?
  exe.write_file          if exe.write?
  exe.edit                if exe.edit?
end
new(options) click to toggle source

Constructor. Sets defaults.

@param [Array] options

# File lib/standup_md/cli.rb, line 44
def initialize(options)
  @edit                = true
  @write               = true
  @append_previous     = true
  @print_current_entry = false
  @json                = false
  @verbose             = false
  @print_all_entries   = false
  @options             = options
  @preferences         = get_preferences
end

Public Instance Methods

append_previous?() click to toggle source

Should `previous_entry_tasks` be appended? If false, previous_entry_tasks will be overwritten.

@return [Boolean] Default is true

# File lib/standup_md/cli.rb, line 203
def append_previous?
  @append_previous
end
append_to_previous_entry_tasks() click to toggle source

Appends entries passed at runtime to existing previous entries.

@return [Hash]

# File lib/standup_md/cli.rb, line 128
def append_to_previous_entry_tasks
  echo 'Appending previous entry tasks'
  additions = preferences.delete('previous_entry_tasks')
  standup.previous_entry_tasks.concat(additions)
end
echo(msg) click to toggle source

Prints output if verbose is true.

@return [nil]

# File lib/standup_md/cli.rb, line 219
def echo(msg)
  puts msg if verbose?
end
edit() click to toggle source

Opens the file in an editor. Abandons the script.

# File lib/standup_md/cli.rb, line 136
def edit
  echo "  Opening file in #{editor}"
  exec("#{editor} #{standup.file}")
end
edit?() click to toggle source

Should the standup file be opened in the editor?

@return [Boolean] Default is true

# File lib/standup_md/cli.rb, line 194
def edit?
  @edit
end
editor() click to toggle source

Tries to determine the editor, first by checking if the user has one set in their preferences. If not, the VISUAL and EDITOR environmental variables are checked. If none of the above are set, defaults to vim.

@return [String] The editor

# File lib/standup_md/cli.rb, line 76
def editor
  @editor ||=
    if preferences.key?('editor')
      echo "Editor set to [#{preferences.key('editor')}] via preferences"
      preferences.delete('editor')
    elsif ENV['VISUAL']
      echo "Editor set to [#{ENV['VISUAL']}] (ENV['VISUAL'])"
      ENV['VISUAL']
    elsif ENV['EDITOR']
      echo "Editor set to [#{ENV['EDITOR']}] (ENV['EDITOR'])"
      ENV['EDITOR']
    else
      echo "Editor set to [vim] (default)"
      'vim'
    end
end
json?() click to toggle source

If printing an entry, should it be printed as json?

@return [Boolean] Default is false

# File lib/standup_md/cli.rb, line 162
def json?
  @json
end
print_all_entries() click to toggle source

Prints all entries to the command line.

@return [nil]

print_all_entries?() click to toggle source

Should all entries be printed? If true, disables editing.

@return [Boolean] Default is false

print_current_entry() click to toggle source

Prints the current entry to the command line.

@return [nil]

# File lib/standup_md/cli.rb, line 113
def print_current_entry
  echo 'Print current entry'
  unless json?
    print_entry(standup.header, standup.current_entry)
    return
  end
  echo '  ...as json'
  entry = {standup.header => standup.current_entry}.to_json
  puts entry
end
print_current_entry?() click to toggle source

Should current entry be printed? If true, disables editing.

@return [Boolean] Default is false

# File lib/standup_md/cli.rb, line 154
def print_current_entry?
  @print_current_entry
end
should_append?() click to toggle source

Did the user pass previous_entry_tasks, and should we append?

@return [Boolean]

# File lib/standup_md/cli.rb, line 211
def should_append?
  preferences.key?('previous_entry_tasks') && append_previous?
end
standup() click to toggle source

Sets up an instance of StandupMD and passes all user preferences.

@return [StandupMD]

# File lib/standup_md/cli.rb, line 60
def standup
  @standup ||= ::StandupMD.new do |s|
    echo 'Runtime options:'
    preferences.each do |k, v|
      echo "  #{k} = #{v}"
      s.send("#{k}=", v)
    end
  end.load
end
verbose?() click to toggle source

Should debug info be printed?

@return [Boolean] Default is false

# File lib/standup_md/cli.rb, line 178
def verbose?
  @verbose
end
write?() click to toggle source

Should the file be written?

@return [Boolean] Default is true

# File lib/standup_md/cli.rb, line 186
def write?
  @write
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 145
def write_file
  echo '  Writing file'
  standup.write
end