module ArchSpec::CLI
The archspec command line. Backs the exe/archspec executable and dispatches the init, check, explain, reflect, and version subcommands.
archspec init archspec check [PATHS...] [--config PATH] [--format text|json] [--update-todo|--check-todo] [--reflect] archspec explain PATH_OR_CONSTANT [--reflect]
run returns the process exit status: 0 when clean, 1 when violations are found (or, with --check-todo, when the todo lists violations that no longer occur).
Constants
- CONFIG_FILE
- REFLECT_HELP
- TEMPLATE
- USAGE_ERROR_STATUS
Public Instance Methods
# File lib/archspec/cli.rb, line 203 def load_definition(config_path) raise Error, "no #{config_path} found; run `archspec init` first" unless File.exist?(config_path) absolute_config = File.expand_path(config_path) definition = Definition.new definition.base_dir = File.dirname(absolute_config) definition.extend(DSL::Context) definition.instance_eval(File.read(absolute_config), absolute_config) if definition.component_specs.empty? && definition.rules.empty? raise Error, "#{config_path} declared no components or rules; the file's top level is already " \ 'the DSL, so do not wrap declarations in ArchSpec.define' end [definition, definition.absolute_root] rescue Error raise rescue SyntaxError, LoadError, StandardError => e detail = e.message.lines.first&.strip || e.class.name raise Error, "could not load #{config_path}: #{detail}" end
Evaluates an Archspec.rb file and returns the definition and its root.
# File lib/archspec/cli.rb, line 31 def run(argv, output: $stdout, error: $stderr) argv = argv.dup command = argv.shift || 'check' case command when 'help', '--help', '-h' help(argv, output) when 'init' init(argv, output) when 'check' check(argv, output, error) when 'explain' explain(argv, output, error) when 'reflect' reflect(argv, output) when 'version', '--version', '-v' raise UsageError, "unexpected argument: #{argv.first}" if argv.any? output.puts ArchSpec::VERSION 0 else raise UsageError, "unknown command: #{command}" end rescue OptionParser::ParseError, UsageError => e error.puts "archspec: error: #{e.message}" error.puts usage(command) USAGE_ERROR_STATUS rescue Error => e error.puts "archspec: error: #{e.message}" 1 end