Class: GitCommander::Command
- Inherits:
-
Object
- Object
- GitCommander::Command
- Includes:
- CommandLoaderOptions
- Defined in:
- lib/git_commander/command.rb,
lib/git_commander/command/option.rb,
lib/git_commander/command/runner.rb,
lib/git_commander/command/loaders/raw.rb,
lib/git_commander/command/configurator.rb,
lib/git_commander/command/loaders/file_loader.rb
Overview
Wraps domain logic for executing git-cmd Commands
Defined Under Namespace
Modules: Loaders Classes: Configurator, Option, Runner
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#output ⇒ Object
Returns the value of attribute output.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
-
#switches ⇒ Object
readonly
Returns the value of attribute switches.
Instance Method Summary collapse
-
#add_option(option_type, options = {}) ⇒ Object
Add to this Command’s #arguments, #flags, or #switches.
-
#help ⇒ Object
Adds command-line help text to the #output of this Command.
-
#initialize(name, registry: nil, **options) {|run_options| ... } ⇒ Command
constructor
A new instance of Command.
-
#options ⇒ Set
Access to a unique Set of this Command’s #arguments, #flags, and #switches.
-
#run(run_options = []) ⇒ Object
Executes the block for the command with the provided run_options.
-
#say(message) ⇒ Object
Appends the
messageto the Command’s #output.
Methods included from CommandLoaderOptions
#argument, #description, #flag, #on_run, #summary, #switch
Constructor Details
#initialize(name, registry: nil, **options) {|run_options| ... } ⇒ Command
Returns a new instance of Command.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/git_commander/command.rb', line 38 def initialize(name, registry: nil, **, &block) @name = name @description = [:description] @summary = [:summary] @block = block_given? ? block : proc {} @registry = registry || GitCommander::Registry.new @output = [:output] || STDOUT () end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
14 15 16 |
# File 'lib/git_commander/command.rb', line 14 def arguments @arguments end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
14 15 16 |
# File 'lib/git_commander/command.rb', line 14 def block @block end |
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
14 15 16 |
# File 'lib/git_commander/command.rb', line 14 def flags @flags end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/git_commander/command.rb', line 14 def name @name end |
#output ⇒ Object
Returns the value of attribute output.
15 16 17 |
# File 'lib/git_commander/command.rb', line 15 def output @output end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
14 15 16 |
# File 'lib/git_commander/command.rb', line 14 def registry @registry end |
#switches ⇒ Object (readonly)
Returns the value of attribute switches.
14 15 16 |
# File 'lib/git_commander/command.rb', line 14 def switches @switches end |
Instance Method Details
#add_option(option_type, options = {}) ⇒ Object
Add to this Command’s #arguments, #flags, or #switches
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/git_commander/command.rb', line 97 def add_option(option_type, = {}) case option_type.to_sym when :argument @arguments << Option.new(**) when :flag @flags << Option.new(**) when :switch @switches << Option.new(**) end end |
#help ⇒ Object
Adds command-line help text to the #output of this Command
68 69 70 71 72 73 74 75 76 |
# File 'lib/git_commander/command.rb', line 68 def help say "NAME" say " git-cmd #{name} – #{summary}" say "USAGE" say " git-cmd #{name} [command options] #{arguments.map { |arg| "[#{arg.name}]" }.join(" ")}" description_help argument_help end |
#options ⇒ Set
Access to a unique Set of this Command’s #arguments, #flags, and #switches
82 83 84 |
# File 'lib/git_commander/command.rb', line 82 def Set.new(@arguments + @flags + @switches) end |
#run(run_options = []) ⇒ Object
Executes the block for the command with the provided run_options.
53 54 55 56 |
# File 'lib/git_commander/command.rb', line 53 def run( = []) assign_option_values() Runner.new(self).run .map(&:to_h).reduce(:merge) end |
#say(message) ⇒ Object
Appends the message to the Command’s #output
62 63 64 |
# File 'lib/git_commander/command.rb', line 62 def say() output.puts end |