Class: Tsumanne::CLI

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/tsumanne/cli.rb

Overview

Command line entry point for the tsumanne executable.

Constant Summary collapse

COMMANDS =

Subcommands, in the order --help lists them.

T.let({
  "threads" => "List the archived threads of a board",
  "thread" => "Print an archived thread, by id or by archive path",
  "search" => "Find the archived thread of a 2chan.net thread URI",
  "indexes" => "List the indexes, or search them by keyword",
  "register" => "Ask the site to archive a 2chan.net thread"
}.freeze, T::Hash[String, String])

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.



34
35
36
37
38
# File 'lib/tsumanne/cli.rb', line 34

def initialize(args)
  @args = T.let(args.dup, T::Array[String])
  # Reassigned to the subcommand parser, so that `--help` educates about the command at hand.
  @parser = T.let(global_parser, Optimist::Parser)
end

Class Method Details

.start(args) ⇒ Object



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

def self.start(args)
  new(args).run
end

Instance Method Details

#runObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/tsumanne/cli.rb', line 41

def run
  execute
  0
rescue Optimist::HelpNeeded
  @parser.educate($stdout)
  0
rescue Optimist::VersionNeeded
  $stdout.puts(@parser.version)
  0
rescue Optimist::CommandlineError, URI::InvalidURIError, Error => e
  warn("Error: #{e.message}")
  1
end