Class: Textus::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/cli.rb,
lib/textus/cli/verb.rb,
lib/textus/cli/group.rb,
lib/textus/cli/verb/mv.rb,
lib/textus/cli/verb/get.rb,
lib/textus/cli/verb/put.rb,
lib/textus/cli/verb/uid.rb,
lib/textus/cli/group/key.rb,
lib/textus/cli/verb/deps.rb,
lib/textus/cli/verb/init.rb,
lib/textus/cli/verb/list.rb,
lib/textus/cli/group/hook.rb,
lib/textus/cli/verb/build.rb,
lib/textus/cli/verb/hooks.rb,
lib/textus/cli/verb/intro.rb,
lib/textus/cli/verb/rdeps.rb,
lib/textus/cli/verb/stale.rb,
lib/textus/cli/verb/where.rb,
lib/textus/cli/verb/accept.rb,
lib/textus/cli/verb/delete.rb,
lib/textus/cli/verb/doctor.rb,
lib/textus/cli/verb/schema.rb,
lib/textus/cli/group/schema.rb,
lib/textus/cli/verb/refresh.rb,
lib/textus/cli/verb/hook_run.rb,
lib/textus/cli/verb/published.rb,
lib/textus/cli/verb/schema_diff.rb,
lib/textus/cli/verb/schema_init.rb,
lib/textus/cli/verb/migrate_keys.rb,
lib/textus/cli/verb/schema_migrate.rb

Defined Under Namespace

Classes: Group, Verb

Constant Summary collapse

VERBS =

verb name → Verb subclass. Adding a new verb is a one-line entry here plus a new file under lib/textus/cli/.

{
  "accept" => Verb::Accept,
  "build" => Verb::Build,
  "delete" => Verb::Delete,
  "deps" => Verb::Deps,
  "doctor" => Verb::Doctor,
  "get" => Verb::Get,
  "hook" => Group::Hook,
  "init" => Verb::Init,
  "intro" => Verb::Intro,
  "key" => Group::Key,
  "list" => Verb::List,
  "published" => Verb::Published,
  "put" => Verb::Put,
  "rdeps" => Verb::Rdeps,
  "refresh" => Verb::Refresh,
  "schema" => Group::Schema,
  "stale" => Verb::Stale,
  "where" => Verb::Where,
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of CLI.



33
34
35
36
37
38
39
# File 'lib/textus/cli.rb', line 33

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



29
30
31
# File 'lib/textus/cli.rb', line 29

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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/textus/cli.rb', line 41

def run(argv)
  OptionParser.new { |o| o.on("--root=PATH") { |v| @root_arg = v } }.order!(argv)
  verb = argv.shift
  raise UsageError.new("missing verb") if verb.nil?

  case verb
  when "--version", "-v" then @stdout.puts(VERSION)
                              0
  when "--help", "-h"    then print_help
                              0
  else
    klass = VERBS[verb] or raise UsageError.new("unknown verb: #{verb}")
    dispatch(klass, argv)
  end
rescue Textus::Error => e
  emit_error(e)
end