Class: Diogenes::Cli::Build

Inherits:
Object
  • Object
show all
Defined in:
lib/diogenes/cli/build.rb

Constant Summary collapse

DIOGENES_DIR =

: String

".diogenes"
SOURCE_SUBDIRS =

: Array

%w[skills rules hooks].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv:, cwd:, out:, err:) ⇒ Build

: (argv: Array, cwd: String, out: IO, err: IO) -> void



18
19
20
21
22
23
24
25
# File 'lib/diogenes/cli/build.rb', line 18

def initialize(argv:, cwd:, out:, err:)
  @argv = argv #: Array[String]
  @cwd = cwd #: String
  @out = out #: IO
  @err = err #: IO
  @build_all = false #: bool
  @target_key = nil #: Symbol?
end

Class Method Details

.run(argv:, cwd:, out:, err:, **_opts) ⇒ Object

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



13
14
15
# File 'lib/diogenes/cli/build.rb', line 13

def self.run(argv:, cwd:, out:, err:, **_opts)
  new(argv:, cwd:, out:, err:).run
end

Instance Method Details

#runObject

: () -> Integer



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/diogenes/cli/build.rb', line 28

def run
  parse_options
  return usage_error unless @build_all || @target_key

  diogenes_dir = File.join(@cwd, DIOGENES_DIR)
  unless Dir.exist?(diogenes_dir)
    @err.puts "No #{DIOGENES_DIR}/ found. Run `diogenes init` first."
    return 1
  end

  Diogenes.reset!
  load_config(diogenes_dir)
  load_sources(diogenes_dir)

  target_keys = @target_key ? [@target_key] : Diogenes.configuration.targets

  if target_keys.empty?
    @err.puts "No targets configured. Add `targets :claude_code, :cursor` to #{DIOGENES_DIR}/diogenes.rb"
    return 1
  end

  sources = Diogenes::Build::Sources.new(
    skills: Diogenes.skills,
    rules: Diogenes.rules,
    hooks: Diogenes.hooks,
    artifacts: Diogenes.artifacts
  )

  built = build_targets(target_keys, sources)
  print_summary(built)
  0
rescue UserError => e
  @err.puts e.message
  1
end