Class: Abt::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/abt/cli.rb,
lib/abt/cli/prompt.rb,
lib/abt/cli/global_commands.rb,
lib/abt/cli/arguments_parser.rb,
lib/abt/cli/global_commands/help.rb,
lib/abt/cli/global_commands/share.rb,
lib/abt/cli/global_commands/readme.rb,
lib/abt/cli/global_commands/version.rb,
lib/abt/cli/global_commands/commands.rb,
lib/abt/cli/global_commands/examples.rb

Defined Under Namespace

Modules: GlobalCommands Classes: Abort, ArgumentsParser, Exit, Prompt

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv: ARGV, input: $stdin, output: $stdout, err_output: $stderr) ⇒ Cli

Returns a new instance of Cli.



15
16
17
18
19
20
21
22
# File 'lib/abt/cli.rb', line 15

def initialize(argv: ARGV, input: $stdin, output: $stdout, err_output: $stderr)
  (@command, *remaining_args) = argv
  @input = input
  @output = output
  @err_output = err_output
  @prompt = Abt::Cli::Prompt.new(output: err_output)
  @aris = ArgumentsParser.new(sanitized_piped_args + remaining_args).parse
end

Instance Attribute Details

#arisObject (readonly)

Returns the value of attribute aris.



13
14
15
# File 'lib/abt/cli.rb', line 13

def aris
  @aris
end

#commandObject (readonly)

Returns the value of attribute command.



13
14
15
# File 'lib/abt/cli.rb', line 13

def command
  @command
end

#err_outputObject (readonly)

Returns the value of attribute err_output.



13
14
15
# File 'lib/abt/cli.rb', line 13

def err_output
  @err_output
end

#inputObject (readonly)

Returns the value of attribute input.



13
14
15
# File 'lib/abt/cli.rb', line 13

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output.



13
14
15
# File 'lib/abt/cli.rb', line 13

def output
  @output
end

#promptObject (readonly)

Returns the value of attribute prompt.



13
14
15
# File 'lib/abt/cli.rb', line 13

def prompt
  @prompt
end

Instance Method Details

#abort(message) ⇒ Object

Raises:



55
56
57
# File 'lib/abt/cli.rb', line 55

def abort(message)
  raise Abort, message
end

#exit_with_message(message) ⇒ Object

Raises:



59
60
61
# File 'lib/abt/cli.rb', line 59

def exit_with_message(message)
  raise Exit, message
end

#performObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/abt/cli.rb', line 24

def perform
  if command.nil?
    warn("No command specified, printing help\n\n")
    @command = "help"
  end

  if global_command?
    process_global_command
  else
    process_aris
  end
end


51
52
53
# File 'lib/abt/cli.rb', line 51

def print(*args)
  output.print(*args)
end


37
38
39
40
41
# File 'lib/abt/cli.rb', line 37

def print_ari(scheme, path, description = nil)
  command = "#{scheme}:#{path}"
  command += " # #{description}" unless description.nil?
  output.puts command
end

#puts(*args) ⇒ Object



47
48
49
# File 'lib/abt/cli.rb', line 47

def puts(*args)
  output.puts(*args)
end

#warn(*args) ⇒ Object



43
44
45
# File 'lib/abt/cli.rb', line 43

def warn(*args)
  err_output.puts(*args)
end