Class: Menuconform::CLI
- Inherits:
-
Object
- Object
- Menuconform::CLI
- Defined in:
- lib/menuconform/cli.rb
Overview
Command-line interface. Exit codes:
0 - check ran and passed the gate (no error-severity findings, or score
at/above --fail-below when given)
1 - check ran and failed the gate
2 - usage error or unreadable input
Constant Summary collapse
- USAGE =
<<~TEXT menuconform — UCP food-ordering menu conformance kit Usage: menuconform check MENU.json [options] Validate a menu (IR, or --from a source format) menuconform import --from FORMAT SRC.json Convert a source export to Menu IR JSON menuconform export MENU.json [options] Export to the pinned UCP catalog draft, reporting EXPORT- lossiness findings menuconform rules List the rule catalog menuconform version Print version Check options: --from FORMAT Treat input as a source export; import to IR first --json Emit the full JSON report instead of text --reference-time TIME ISO 8601 instant for time-dependent rules (default: now; pin it for reproducible runs) --fail-below SCORE Exit 1 when the score is below SCORE (default gate: exit 1 on any error finding) Import options: --from FORMAT Source format (required; see below) --config PATH Override the importer's default mapping config -o, --out PATH Write IR JSON to PATH (default: stdout) TEXT
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(stdout:, stderr:) ⇒ CLI
constructor
A new instance of CLI.
- #run(argv) ⇒ Object
Constructor Details
#initialize(stdout:, stderr:) ⇒ CLI
Returns a new instance of CLI.
43 44 45 46 |
# File 'lib/menuconform/cli.rb', line 43 def initialize(stdout:, stderr:) @stdout = stdout @stderr = stderr end |
Class Method Details
.run(argv, stdout: $stdout, stderr: $stderr) ⇒ Object
39 40 41 |
# File 'lib/menuconform/cli.rb', line 39 def self.run(argv, stdout: $stdout, stderr: $stderr) new(stdout: stdout, stderr: stderr).run(argv) end |
Instance Method Details
#run(argv) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/menuconform/cli.rb', line 48 def run(argv) case argv.first when "check" then check(argv[1..]) when "import" then import(argv[1..]) when "export" then export(argv[1..]) when "rules" then rules when "version", "--version", "-v" then @stdout.puts(VERSION) || 0 when "help", "--help", "-h" then @stdout.puts(USAGE) || 0 when nil then @stderr.puts(USAGE) || 2 else @stderr.puts "unknown command: #{argv.first}\n\n#{USAGE}" 2 end end |