Module: Huebot::CLI
- Defined in:
- lib/huebot/cli.rb
Overview
Helpers for running huebot in cli-mode.
Defined Under Namespace
Classes: Options
Class Method Summary collapse
-
.check!(programs, io, quiet: false) ⇒ Object
Prints any program errors or warnings, and returns a boolean for each.
-
.get_cmd ⇒ Symbol
Returns the command given to huebot.
-
.get_input! ⇒ Huebot::CLI::Options, Array<Huebot::ProgramSrc>
Parses and returns input from the CLI.
-
.help! ⇒ Object
Print help and exit.
Class Method Details
.check!(programs, io, quiet: false) ⇒ Object
Prints any program errors or warnings, and returns a boolean for each.
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/huebot/cli.rb', line 57 def self.check!(programs, io, quiet: false) if (invalid_progs = programs.select { |prog| prog.errors.any? }).any? io, "Errors", invalid_progs, :errors unless quiet end if (imperfect_progs = programs.select { |prog| prog.warnings.any? }).any? puts "" if invalid_progs.any? io, "Warnings", imperfect_progs, :warnings unless quiet end return invalid_progs.any?, imperfect_progs.any? end |
.get_cmd ⇒ Symbol
Returns the command given to huebot.
22 23 24 |
# File 'lib/huebot/cli.rb', line 22 def self.get_cmd ARGV[0].to_s.to_sym end |
.get_input! ⇒ Huebot::CLI::Options, Array<Huebot::ProgramSrc>
Parses and returns input from the CLI. Serious errors might result in the program exiting.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/huebot/cli.rb', line 32 def self.get_input! , parser = option_parser parser.parse! files = ARGV[1..-1] if files.empty? puts parser.help exit 1 elsif (bad_paths = files.select { |p| !File.exists? p }).any? $stderr.puts "Cannot find #{bad_paths.join ', '}" exit 1 else return , files.map { |path| ProgramSrc.new(YAML.load_file(path), path) } end end |
.help! ⇒ Object
Print help and exit
71 72 73 74 75 |
# File 'lib/huebot/cli.rb', line 71 def self.help! _, parser = option_parser puts parser.help exit 1 end |