Module: Agent::Lock::CLI

Defined in:
lib/agent/lock/cli.rb,
lib/agent/lock/cli.rb,
lib/agent/lock/cli/commands/base.rb,
lib/agent/lock/cli/commands/list.rb,
lib/agent/lock/cli/commands/mine.rb,
lib/agent/lock/cli/commands/note.rb,
lib/agent/lock/cli/commands/break.rb,
lib/agent/lock/cli/commands/check.rb,
lib/agent/lock/cli/commands/skill.rb,
lib/agent/lock/cli/commands/resume.rb,
lib/agent/lock/cli/commands/whoami.rb,
lib/agent/lock/cli/commands/acquire.rb,
lib/agent/lock/cli/commands/release.rb,
lib/agent/lock/cli/commands/version.rb,
lib/agent/lock/cli/commands/completion.rb,
lib/agent/lock/cli/commands/release_all.rb

Overview

The command line, and nothing else. Every command here is a thin shell: parse flags, call one Manager method, print the result, set an exit code. No command decides anything a library object could decide instead.

Defined Under Namespace

Modules: Commands

Constant Summary collapse

PROGRAM_NAME =

What the gem is installed as. Taken from the gemspec's one executable rather than from $PROGRAM_NAME, which under a test runner is the runner. The completion script it emits names the program in every line, so guessing it wrong is not a cosmetic mistake.

"alock"
COMMANDS =
{
  "acquire" => [Commands::Acquire, []],
  "release" => [Commands::Release, []],
  "check" => [Commands::Check, []],
  "list" => [Commands::List, ["ls"]],
  "mine" => [Commands::Mine, []],
  "release-all" => [Commands::ReleaseAll, []],
  "break" => [Commands::Break, []],
  "note" => [Commands::Note, []],
  "resume" => [Commands::Resume, []],
  "whoami" => [Commands::Whoami, []],
  "skill path" => [Commands::SkillPath, []],
  "skill install" => [Commands::SkillInstall, []],
  "version" => [Commands::Version, %w[-v --version]]
}.freeze

Class Method Summary collapse

Class Method Details

.registry_for(launcher) ⇒ Dry::CLI::Registry

A registry whose commands are already bound to this launcher, so a command writes to the streams it was given rather than to the process's.

Parameters:

Returns:

  • (Dry::CLI::Registry)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/agent/lock/cli.rb', line 23

def self.registry_for(launcher)
  # `extend` and `register` have to be sent to the new class explicitly.
  # Inside a `tap` block `self` is still this module, so writing them
  # bare turned Agent::Lock::CLI itself into the registry, handed back a
  # class that knew no commands, and left the completion command bound
  # to that empty class.
  registry = Class.new { extend Dry::CLI::Registry }

  COMMANDS.each do |name, (klass, aliases)|
    registry.register(name, klass.new(launcher), aliases: aliases)
  end

  registry.register("completion", Commands::Completion[registry, program_name: PROGRAM_NAME])
  registry
end