Class: Spreen::Wiki::CLI
- Inherits:
-
Object
- Object
- Spreen::Wiki::CLI
- Defined in:
- lib/spreen/wiki/cli.rb,
sig/generated/spreen/wiki/cli.rbs
Overview
Command line interface behind the spreen executable:
spreen <update|count-report|llm-export> [options].
Constant Summary collapse
- HELP =
<<~HELP Usage: spreen <command> [options] Commands: update Regenerate Home.md and _Sidebar.md from the wiki tree count-report Export a count report of the unknown-namespace wikis llm-export Export the unknown-namespace wiki list for an LLM version Print the version Run `spreen <command> --help` to list the command's options. HELP
- COMMON_OPTIONS =
Flags shared by every command, mapped to the keyword arguments of the underlying classes. --exclude and the per-command flags are wired up separately because they need a type or a fixed value.
{ '--path PATH' => [:base_path, 'Path to the wiki clone (default: current directory)'], '--group-by GROUP_BY' => [:group_by, 'Grouping criteria (default: Owner)'], '--language LANGUAGE' => [:language, 'Language of the labels (default: English)'], '--org ORGANISATION' => [:organisation, 'GitHub organisation/user hosting the wiki'], '--repo REPOSITORY' => [:repository, 'GitHub repository whose wiki is organised'], '--wiki-url URL' => [:wiki_url, 'Wiki URL (overrides the one derived from --org/--repo)'], '--template-dir DIR' => [:template_dir, 'Directory of <group_by>/<language>.md Home templates'], '--config FILE' => [:config_path, 'Config file path (default: <path>/.spreen.yml)'] }.freeze
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #add_command_options(opt, command) ⇒ void
- #add_common_options(opt) ⇒ void
- #count_report ⇒ void
- #execute(command) ⇒ Integer
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
- #llm_export ⇒ void
- #parser(command) ⇒ OptionParser
- #print_help(command) ⇒ Integer
- #print_version ⇒ Integer
- #run ⇒ Integer
- #unknown_command(command) ⇒ Integer
- #update ⇒ void
Constructor Details
#initialize(argv) ⇒ CLI
Returns a new instance of CLI.
50 51 52 53 |
# File 'lib/spreen/wiki/cli.rb', line 50 def initialize(argv) @argv = argv.dup @options = { base_path: Dir.pwd, group_by: 'Owner', language: 'English', home_overflow: 'false' } end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
68 69 70 |
# File 'lib/spreen/wiki/cli.rb', line 68 def argv @argv end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
68 69 70 |
# File 'lib/spreen/wiki/cli.rb', line 68 def @options end |
Class Method Details
.start(argv = ARGV) ⇒ Integer
44 45 46 |
# File 'lib/spreen/wiki/cli.rb', line 44 def self.start(argv = ARGV) new(argv).run end |
Instance Method Details
#add_command_options(opt, command) ⇒ void
This method returns an undefined value.
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/spreen/wiki/cli.rb', line 146 def (opt, command) if command == 'update' opt.on('--overflow', 'Split Home into per-namespace pages under wikis-by-owner/') do [:home_overflow] = 'true' end else opt.on('--output FILENAME', 'Export filename (relative to --path unless absolute)') do |filename| [:output] = filename end end end |
#add_common_options(opt) ⇒ void
This method returns an undefined value.
134 135 136 137 138 139 140 141 |
# File 'lib/spreen/wiki/cli.rb', line 134 def (opt) COMMON_OPTIONS.each do |flag, (key, description)| opt.on(flag, description) { |value| [key] = value } end opt.on('--exclude DIR1,DIR2', Array, 'Directories to skip while scanning') do |dirs| [:excluded_dirs] = dirs end end |
#count_report ⇒ void
This method returns an undefined value.
111 112 113 114 115 |
# File 'lib/spreen/wiki/cli.rb', line 111 def count_report count_list_by_namespace, path_to_export = UnknownWikiCountListExporter.run(**) puts count_list_by_namespace puts "Exported the unknown wiki count report to '#{path_to_export}'." end |
#execute(command) ⇒ Integer
72 73 74 75 76 77 78 79 |
# File 'lib/spreen/wiki/cli.rb', line 72 def execute(command) parser(command).parse!(argv) __send__(command.tr('-', '_')) 0 rescue ArgumentError, OptionParser::ParseError => e warn e. 1 end |
#llm_export ⇒ void
This method returns an undefined value.
118 119 120 121 |
# File 'lib/spreen/wiki/cli.rb', line 118 def llm_export path_to_export = UnknownWikiListExporterForLLM.run(**) puts "Exported the unknown wiki list for LLM to '#{path_to_export}'." end |
#parser(command) ⇒ OptionParser
125 126 127 128 129 130 |
# File 'lib/spreen/wiki/cli.rb', line 125 def parser(command) OptionParser.new("Usage: spreen #{command} [options]") do |opt| (opt) (opt, command) end end |
#print_help(command) ⇒ Integer
89 90 91 92 |
# File 'lib/spreen/wiki/cli.rb', line 89 def print_help(command) puts HELP command.nil? ? 1 : 0 end |
#print_version ⇒ Integer
82 83 84 85 |
# File 'lib/spreen/wiki/cli.rb', line 82 def print_version puts VERSION 0 end |
#run ⇒ Integer
56 57 58 59 60 61 62 63 64 |
# File 'lib/spreen/wiki/cli.rb', line 56 def run command = argv.shift case command when 'update', 'count-report', 'llm-export' then execute(command) when 'version', '--version', '-v' then print_version when nil, 'help', '--help', '-h' then print_help(command) else unknown_command(command) end end |
#unknown_command(command) ⇒ Integer
96 97 98 99 100 |
# File 'lib/spreen/wiki/cli.rb', line 96 def unknown_command(command) warn "Unknown command: `#{command}`" warn HELP 1 end |