Module: Configliere::GitStyleBinaries

Defined in:
lib/configliere/git_style_binaries.rb

Overview

Command line tool to manage param info

To include, specify

Configliere.use :git_style_binaries

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commandObject

Returns the value of attribute command.



21
22
23
# File 'lib/configliere/git_style_binaries.rb', line 21

def command
  @command
end

Instance Method Details

#base_script_nameObject

The script name without command appendix if any: For $0 equal to any of ‘git’, ‘git-reset’, or ‘git-cherry-pick’, base_script_name is ‘git’



45
46
47
# File 'lib/configliere/git_style_binaries.rb', line 45

def base_script_name
  raw_script_name.gsub(/-.*/, '')
end

#helpObject

The contents of the help message. Dumps the standard commandline help message, and then lists the commands with their description.



51
52
53
54
55
56
57
58
59
60
# File 'lib/configliere/git_style_binaries.rb', line 51

def help
  help_str = super()
  help_str << "\n\nCommands:\n"
  COMMANDS.map do |cmd, cmd_params, desc|
    cmd_template = "  %-49s" % [base_script_name, cmd, cmd_params].join(" ")
    cmd_template += " :: " + desc if desc
    help_str << cmd_template+"\n"
  end
  help_str
end

#process_argv!Object

Parse the command-line args into the params hash.

‘–happy_flag’ produces :happy_flag => true in the params hash ‘–foo=foo_val’ produces :foo => ‘foo_val’ in the params hash. ‘–’ Stop parsing; all remaining args are piled into :rest

self.rest contains all arguments that don’t start with a ‘–’

and all args following the '--' sentinel if any.


33
34
35
36
37
38
39
40
# File 'lib/configliere/git_style_binaries.rb', line 33

def process_argv!
  super
  if raw_script_name =~ /(\w+)-([\w\-]+)/
    self.command = $2
  else
    self.command = rest.shift
  end
end

#usageObject

Usage line



63
64
65
# File 'lib/configliere/git_style_binaries.rb', line 63

def usage
  %Q{usage: #{base_script_name} command [...--param=val...]}
end