Class: Textus::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/cli.rb

Overview

rubocop:disable Metrics/ClassLength

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdin:, stdout:, stderr:, cwd:) ⇒ CLI

Returns a new instance of CLI.



14
15
16
17
18
19
20
# File 'lib/textus/cli.rb', line 14

def initialize(stdin:, stdout:, stderr:, cwd:)
  @stdin = stdin
  @stdout = stdout
  @stderr = stderr
  @cwd = cwd
  @root_arg = nil
end

Class Method Details

.run(argv, stdin: $stdin, stdout: $stdout, stderr: $stderr, cwd: Dir.pwd) ⇒ Object



10
11
12
# File 'lib/textus/cli.rb', line 10

def self.run(argv, stdin: $stdin, stdout: $stdout, stderr: $stderr, cwd: Dir.pwd)
  new(stdin: stdin, stdout: stdout, stderr: stderr, cwd: cwd).run(argv)
end

Instance Method Details

#run(argv) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/textus/cli.rb', line 22

def run(argv) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize
  OptionParser.new do |o|
    o.on("--root=PATH") { |v| @root_arg = v }
  end.order!(argv)
  verb = argv.shift
  raise UsageError.new("missing verb") if verb.nil?

  case verb
  when "list"   then verb_list(argv)
  when "where"  then verb_where(argv)
  when "get"    then verb_get(argv)
  when "put"    then verb_put(argv)
  when "schema" then verb_schema(argv)
  when "stale"  then verb_stale(argv)
  when "delete"       then verb_delete(argv)
  when "validate-all" then verb_validate_all(argv)
  when "build"        then verb_build(argv)
  when "deps"         then verb_deps(argv)
  when "rdeps"        then verb_rdeps(argv)
  when "published"    then verb_published(argv)
  when "accept"       then verb_accept(argv)
  when "init"         then verb_init(argv)
  when "schema-init"    then verb_schema_init(argv)
  when "schema-diff"    then verb_schema_diff(argv)
  when "schema-migrate" then verb_schema_migrate(argv)
  when "action"         then verb_action(argv)
  when "refresh"        then verb_refresh(argv)
  when "extensions"     then verb_extensions(argv)
  when "migrate-keys"   then verb_migrate_keys(argv)
  when "mv"             then verb_mv(argv)
  when "uid"            then verb_uid(argv)
  when "doctor"         then verb_doctor(argv)
  when "intro"          then verb_intro(argv)
  when "--version", "-v" then @stdout.puts(VERSION)
                              0
  when "--help", "-h"    then print_help
                              0
  else raise UsageError.new("unknown verb: #{verb}")
  end
rescue Textus::Error => e
  emit_error(e)
end