Class: Diogenes::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/diogenes/cli.rb,
lib/diogenes/cli/init.rb,
lib/diogenes/cli/build.rb,
lib/diogenes/cli/watch.rb,
lib/diogenes/cli/evaluate.rb,
lib/diogenes/cli/validate.rb,
sig/generated/diogenes/cli.rbs,
sig/generated/diogenes/cli/init.rbs,
sig/generated/diogenes/cli/build.rbs,
sig/generated/diogenes/cli/evaluate.rbs

Defined Under Namespace

Classes: Build, Evaluate, Init, Validate, Watch

Constant Summary collapse

COMMANDS =

Returns:

  • (Hash[String, Class])
{
  "init" => Init,
  "build" => Build,
  "evaluate" => Evaluate,
  "validate" => Validate,
  "watch" => Watch
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv:, out:, err:, **opts) ⇒ Cli

: (argv: Array, out: IO, err: IO, **untyped) -> void

Parameters:

  • argv: (Array[String])
  • out: (IO)
  • err: (IO)
  • (Object)


26
27
28
29
30
31
32
# File 'lib/diogenes/cli.rb', line 26

def initialize(argv:, out:, err:, **opts)
  @argv = argv.dup #: Array[String]
  @out = out #: IO
  @err = err #: IO
  @in = opts.fetch(:in, $stdin) #: IO
  @cwd = opts.fetch(:cwd, Dir.pwd) #: String
end

Class Method Details

.run(argv = ARGV, out: $stdout, err: $stderr, **opts) ⇒ Integer

: (?Array argv, ?out: IO, ?err: IO, **untyped) -> Integer

Parameters:

  • argv (Array[String]) (defaults to: ARGV)
  • out: (IO) (defaults to: $stdout)
  • err: (IO) (defaults to: $stderr)
  • (Object)

Returns:

  • (Integer)


21
22
23
# File 'lib/diogenes/cli.rb', line 21

def self.run(argv = ARGV, out: $stdout, err: $stderr, **opts)
  new(argv: argv, out: out, err: err, **opts).run
end

Instance Method Details

: () -> Integer

Returns:

  • (Integer)


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/diogenes/cli.rb', line 62

def print_help
  @out.puts <<~HELP
    Diogenes - The Ruby AI Feature Gatekeeper

    Usage:
      diogenes <command> [options]

    Description:
      Diogenes is a Ruby gem that holds your AI features to the same light. It has two jobs:
      1. A five-gate gauntlet decision framework that determines whether something should be an AI feature in production, or whether it's a software problem in disguise. Derived from Ruby's core principles: least surprise, programmer happiness, and human-centered design.
      2. An agent configuration build tool that lets you write your AI agent skills, rules, and hooks once in a canonical Ruby DSL, and Diogenes builds the right configuration for every agent you use: Claude Code, Cursor, Copilot, Codex, Gemini, and more.

    Commands:
      init      Initialize a new Diogenes project
      build     Build the Diogenes agent configuration for a given target
      evaluate  Evaluate a proposed AI feature through the five gates
      validate  Validate the Diogenes agent configuration for a given target
      watch     Watch .diogenes/ and rebuild on changes
      help      Show help for a command
      version   Show version information
  HELP
  0
end

: () -> Integer

Returns:

  • (Integer)


87
88
89
90
# File 'lib/diogenes/cli.rb', line 87

def print_version
  @out.puts(Diogenes::VERSION)
  0
end

#runInteger

: () -> Integer

Returns:

  • (Integer)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/diogenes/cli.rb', line 35

def run
  command, *args = @argv

  case command
  when nil, "help", "-h", "--help"
    print_help
  when "version", "-v", "--version"
    print_version
  when *COMMANDS.keys
    run_command(COMMANDS.fetch(command), args)
  else
    raise UserError, unknown_command_message(command)
  end
rescue OptionParser::ParseError, UserError => e
  @err.puts e.message
  1
end

#run_command(command_class, args) ⇒ Integer

: (Class, Array) -> Integer

Parameters:

  • (Class)
  • (Array[String])

Returns:

  • (Integer)


56
57
58
59
# File 'lib/diogenes/cli.rb', line 56

def run_command(command_class, args)
  opts = {in: @in, cwd: @cwd}
  command_class.run(argv: args, cwd: @cwd, out: @out, err: @err, **opts)
end

#unknown_command_message(command) ⇒ String

: (String) -> String

Parameters:

  • (String)

Returns:

  • (String)


95
96
97
98
99
100
101
# File 'lib/diogenes/cli.rb', line 95

def unknown_command_message(command)
  <<~MESSAGE.strip
    Unknown command: #{command}

    Run `diogenes help` to see available commands.
  MESSAGE
end