Class: Whodunit::Chronicles::CLI
- Inherits:
-
Object
- Object
- Whodunit::Chronicles::CLI
- Defined in:
- lib/whodunit/chronicles/cli.rb
Overview
Small operational command-line interface for ledger lifecycle tasks.
The CLI owns book preparation, migration-like operations, index creation, verification, and status checks. The runtime chronicler only appends entries into a ledger it has been handed.
Class Method Summary collapse
-
.run(argv, out: $stdout, err: $stderr) ⇒ Integer
Run a command with argv-style arguments.
Instance Method Summary collapse
-
#initialize(argv:, out:, err:) ⇒ CLI
constructor
Create a CLI instance.
-
#run ⇒ Integer
Execute the requested command.
Constructor Details
#initialize(argv:, out:, err:) ⇒ CLI
Create a CLI instance.
31 32 33 34 35 |
# File 'lib/whodunit/chronicles/cli.rb', line 31 def initialize(argv:, out:, err:) @argv = argv.dup @out = out @err = err end |
Class Method Details
.run(argv, out: $stdout, err: $stderr) ⇒ Integer
Run a command with argv-style arguments.
22 23 24 |
# File 'lib/whodunit/chronicles/cli.rb', line 22 def self.run(argv, out: $stdout, err: $stderr) new(argv: argv, out: out, err: err).run end |
Instance Method Details
#run ⇒ Integer
Execute the requested command.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/whodunit/chronicles/cli.rb', line 40 def run return usage(0) if @argv.empty? || @argv.first == 'help' namespace = @argv.shift command = @argv.shift config_path = @argv.shift = @argv.dup return usage(1) unless namespace == 'ledger' && command && config_path ledger = LedgerFactory.build(load_config(config_path)) execute_ledger_command(ledger, command, ) rescue StandardError => e @err.puts(e.) 1 end |