Class: Graphomaton::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/graphomaton/cli.rb,
lib/graphomaton/cli/config.rb

Defined Under Namespace

Classes: Config

Constant Summary collapse

EXIT_SUCCESS =
0
EXIT_USAGE =
2
EXIT_INPUT =
3
EXIT_VALIDATION =
4
EXIT_LAYOUT =
5
EXIT_EXPORT =
6
EXIT_SECURITY =
7
COMMANDS =
%w[render validate themes list doctor completion man].freeze
COMPLETION_SHELLS =
%w[bash zsh fish].freeze
COMPLETION_WORDS =
%w[
  render validate themes list doctor completion man formats layouts converters
  --input --input-format --output --format --config --no-clobber --force --validate
  --no-validate --diagnostics --fail-on-warning --strict-semantics --layout-warnings
  --width --height --theme --theme-file --layout --direction --fit --padding
  --node-spacing --rank-spacing --force-iterations --layout-seed --graphviz-command
  --max-metadata-depth --max-label-length --max-group-depth
  --responsive --state-radius --state-shape --edge-style --wrap-labels --title
  --description --cdn --offline --inline-mermaid --inline-mathjax --self-contained
  --nonce --csp --csp-policy --mermaid-sha256 --mathjax-sha256 --version --help
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(stdin: $stdin, stdout: $stdout, stderr: $stderr) ⇒ CLI

Returns a new instance of CLI.



30
31
32
33
34
# File 'lib/graphomaton/cli.rb', line 30

def initialize(stdin: $stdin, stdout: $stdout, stderr: $stderr)
  @stdin = stdin
  @stdout = stdout
  @stderr = stderr
end

Instance Method Details

#run(arguments = ARGV) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/graphomaton/cli.rb', line 36

def run(arguments = ARGV)
  @debug = arguments.include?('--debug')
  catch(:graphomaton_cli_exit) do
    execute(arguments.dup)
    EXIT_SUCCESS
  end
rescue OptionParser::ParseError => e
  report_exception(e)
  EXIT_USAGE
rescue JSON::ParserError, Psych::Exception, ArgumentError, SystemCallError => e
  report_exception(e)
  EXIT_INPUT
rescue Graphomaton::SecurityError => e
  report_exception(e)
  EXIT_SECURITY
rescue Graphomaton::LayoutError => e
  report_exception(e)
  EXIT_LAYOUT
rescue Graphomaton::Error => e
  report_exception(e)
  EXIT_EXPORT
end