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

Overview

rubocop:disable Metrics/ClassLength

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
# 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)
end

Instance Attribute Details

#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

#remaining_argsObject (readonly)

Returns the value of attribute remaining_args.



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

def remaining_args
  @remaining_args
end

Instance Method Details

#abort(message) ⇒ Object

Raises:



53
54
55
# File 'lib/abt/cli.rb', line 53

def abort(message)
  raise Abort, message
end

#arisObject



61
62
63
# File 'lib/abt/cli.rb', line 61

def aris
  @aris ||= ArgumentsParser.new(sanitized_piped_args + remaining_args).parse
end

#directory_configObject



65
66
67
# File 'lib/abt/cli.rb', line 65

def directory_config
  @directory_config ||= Abt::DirectoryConfig.new
end

#exit_with_message(message) ⇒ Object

Raises:



57
58
59
# File 'lib/abt/cli.rb', line 57

def exit_with_message(message)
  raise Exit, message
end

#performObject



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

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

  return process_alias if alias?
  return process_global_command if global_command?

  process_aris
end


49
50
51
# File 'lib/abt/cli.rb', line 49

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


35
36
37
38
39
# File 'lib/abt/cli.rb', line 35

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

#puts(*args) ⇒ Object



45
46
47
# File 'lib/abt/cli.rb', line 45

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

#warn(*args) ⇒ Object



41
42
43
# File 'lib/abt/cli.rb', line 41

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