Class: Coat::CLI

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

Overview

Command line front end: parse argv, delegate, format. Every command returns the process exit status.

Constant Summary collapse

STATE_DIR =
".coat"
LEDGER_FILE =
"ledger.jsonl"
PATCHES_DIR =
"patches"
DEFAULT_OUTPUT =
"coat.html"
DEFAULT_KEY =
"default"
COMMANDS =
{
  "add" => :add, "patches" => :patches, "seams" => :seams, "mend" => :mend,
  "build" => :build, "verify" => :verify, "pin" => :pin,
  "hook" => :hook, "install" => :install,
  "help" => :help, "version" => :version
}.freeze
USAGE =
<<~TEXT
  coat-of-many-colors - stitches what your agents left behind into one thing you can read

  Usage: coat <command> [options]

    add --from CMD    run CMD, keep its output as a patch
    add --file PATH   take an existing file as a patch
    pin               mark where the working tree stands, for --since
    patches           list the scraps collected so far
    seams             where two sources touched the same ground
    mend PATH         say that seam is settled; only a person can
    build             stitch the coat into a single HTML file
    verify            walk the hash chain and report the first break
    install           wire coat into Claude Code's hooks and stop typing this
    hook              read one Claude Code hook payload on stdin
    version           print the version

  Options for mend:
    --by NAME         who settled it (default: your git or login name)
    --note TEXT       why, for whoever reads the coat later

  Options for add:
    --label TEXT      what to call this patch (default: the command)
    --agent NAME      who made it (default: "unknown"); sets its patch color
    --claims A,B      declare what it touched, instead of asking git
    --cwd DIR         where to run it (default: here)
    --cmd CMD         what produced --file, when something else ran it
    --exit N          how that command exited; a non-zero patch is torn
    --since [KEY]     claim whatever moved since that pin (default: #{DEFAULT_KEY})

  Options for pin:
    --key KEY         which pin to set (default: #{DEFAULT_KEY})
    --cwd DIR         which working tree to look at (default: here)

  Options for install:
    --settings PATH   which settings file to wire (default: #{Install::SETTINGS})
    --tools LIST      which tools to watch (default: #{Install::DEFAULT_TOOLS})

  Options for build:
    -o, --output PATH  where to write (default: #{DEFAULT_OUTPUT})
    --title TEXT       the coat's title
TEXT

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



71
72
73
74
# File 'lib/coat/cli.rb', line 71

def initialize(argv)
  @options = {}
  @argv = argv
end

Class Method Details

.run(argv) ⇒ Object



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

def self.run(argv)
  new(argv).run
end

Instance Method Details

#runObject



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/coat/cli.rb', line 76

def run
  @argv = parse(@argv)
  command = @options[:help] ? "help" : (@argv.shift || "help")
  handler = COMMANDS[command] or
    return complain("unknown command #{command.inspect}\n\n#{USAGE}")

  status = send(handler)
  status.is_a?(Integer) ? status : 0
rescue Error, OptionParser::ParseError => e
  complain(e.message)
end