Module: Clue::CLI

Included in:
Clue
Defined in:
lib/clue/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commandObject

Returns the value of attribute command.



4
5
6
# File 'lib/clue/cli.rb', line 4

def command
  @command
end

#dry_runObject Also known as: dry_run?

Verbose, dry run readers & aliases



7
8
9
# File 'lib/clue/cli.rb', line 7

def dry_run
  @dry_run
end

#verboseObject Also known as: verbose?

Verbose, dry run readers & aliases



7
8
9
# File 'lib/clue/cli.rb', line 7

def verbose
  @verbose
end

Instance Method Details

#callObject

Print and/or execute command

Raises:

  • (ArgumentError)


40
41
42
43
44
45
46
47
48
49
# File 'lib/clue/cli.rb', line 40

def call
  raise ArgumentError, 'a command is expected' unless @command

  before_call if self.respond_to?(:before_call)

  print if dry_run? || verbose?
  system(cli_command) unless dry_run?

  after_call if self.respond_to?(:after_call)
end

#cli_commandObject

Command as a string



30
31
32
# File 'lib/clue/cli.rb', line 30

def cli_command
  cli_command_array.join(' ')
end

#cli_command_arrayObject

Command as an array



23
24
25
26
27
# File 'lib/clue/cli.rb', line 23

def cli_command_array
  [@command, cli_options, cli_arguments, cli_streams].each_with_object([]) do |string, memo|
    memo << string if string && string != ''
  end
end

Print command



35
36
37
# File 'lib/clue/cli.rb', line 35

def print
  puts cli_command
end