Class: Lyman::CLI::Root

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

Overview

The legible table of contents for every lyman command. Root wires Thor's argument parsing to a plain object per command (lib/lyman/cli/commands/*.rb) and nothing else — no command grows its body here.

Command contract: every command class is built as Commands::X.new(thor, source_root:).call(*args).

  • thor is this Root instance, passed through so a command can use Thor's UI helpers (thor.yes?, thor.say) without inheriting from Thor itself — commands are plain objects, not Thor subclasses.
  • source_root: is where artifacts are read from (the gem tree by default; overridable via LYMAN_SOURCE_ROOT so tests can point it at a fixture that simulates a newer lyman release).
  • #call's positional args are whatever the command needs (an artifact/project name, or nothing). Project-root discovery (Manifest.find!) happens inside each command that needs it — new is the one command that doesn't have a project root yet.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/lyman/cli.rb', line 34

def self.exit_on_failure?
  true
end

Instance Method Details

#add(artifact) ⇒ Object



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

def add(artifact)
  Commands::Add.new(self, source_root: source_root).call(artifact, force: options[:force])
end

#diff(artifact) ⇒ Object



62
63
64
# File 'lib/lyman/cli.rb', line 62

def diff(artifact)
  Commands::Diff.new(self, source_root: source_root).call(artifact)
end

#doctorObject



67
68
69
# File 'lib/lyman/cli.rb', line 67

def doctor
  Commands::Doctor.new(self, source_root: source_root).call
end

#eject(artifact) ⇒ Object



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

def eject(artifact)
  Commands::Eject.new(self, source_root: source_root).call(artifact)
end

#listObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/lyman/cli.rb', line 72

def list
  manifest_root = Manifest.find
  manifest = Manifest.load(manifest_root) if manifest_root

  Registry::ARTIFACTS.each do |name, spec|
    status =
      if manifest
        entry = manifest.artifact(name)
        entry ? entry["status"] : "not planted"
      end

    role = "#{spec[:role]}#{", opt-in" if spec[:optional]}"
    line = "#{name} (#{role}) #{spec[:dest]}#{"#{status}" if status}#{spec[:description]}"
    say line
  end
end

#new(name) ⇒ Object



39
40
41
# File 'lib/lyman/cli.rb', line 39

def new(name)
  Commands::New.new(self, source_root: source_root).call(name)
end

#updateObject



52
53
54
# File 'lib/lyman/cli.rb', line 52

def update
  Commands::Update.new(self, source_root: source_root).call
end

#versionObject



90
91
92
# File 'lib/lyman/cli.rb', line 90

def version
  say VERSION
end