Class: Diogenes::Cli::Build
- Inherits:
-
Object
- Object
- Diogenes::Cli::Build
- Defined in:
- lib/diogenes/cli/build.rb,
sig/generated/diogenes/cli/build.rbs
Constant Summary collapse
- DIOGENES_DIR =
: String
".diogenes"- SOURCE_SUBDIRS =
: Array
%w[skills rules hooks].freeze
Class Method Summary collapse
-
.run(argv:, cwd:, out:, err:, **_opts) ⇒ Integer
: (argv: Array, cwd: String, out: IO, err: IO, **untyped) -> Integer.
Instance Method Summary collapse
-
#build_targets(keys, sources) ⇒ Array[Hash[Symbol, untyped]]
: (Array, untyped) -> Array[Hash[Symbol, untyped]].
-
#initialize(argv:, cwd:, out:, err:) ⇒ Build
constructor
: (argv: Array, cwd: String, out: IO, err: IO) -> void.
-
#load_config(dir) ⇒ void
: (String) -> void.
-
#load_sources(dir) ⇒ void
: (String) -> void.
-
#parse_options ⇒ void
: () -> void.
-
#print_summary(built) ⇒ void
: (Array[Hash[Symbol, untyped]]) -> void.
-
#run ⇒ Integer
: () -> Integer.
-
#usage_error ⇒ Integer
: () -> Integer.
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) ⇒ Integer
: (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
#build_targets(keys, sources) ⇒ Array[Hash[Symbol, untyped]]
: (Array, untyped) -> Array[Hash[Symbol, untyped]]
95 96 97 98 99 100 101 |
# File 'lib/diogenes/cli/build.rb', line 95 def build_targets(keys, sources) keys.map do |key| target = Targets.for(key, cwd: @cwd, out: @out) files = target.build(sources:) {key:, files:} end end |
#load_config(dir) ⇒ void
This method returns an undefined value.
: (String) -> void
82 83 84 85 |
# File 'lib/diogenes/cli/build.rb', line 82 def load_config(dir) config = File.join(dir, "diogenes.rb") load config if File.exist?(config) end |
#load_sources(dir) ⇒ void
This method returns an undefined value.
: (String) -> void
88 89 90 91 92 |
# File 'lib/diogenes/cli/build.rb', line 88 def load_sources(dir) SOURCE_SUBDIRS.each do |subdir| Dir.glob(File.join(dir, subdir, "**/*.rb")).sort.each { |f| load f } end end |
#parse_options ⇒ void
This method returns an undefined value.
: () -> void
67 68 69 70 71 72 |
# File 'lib/diogenes/cli/build.rb', line 67 def OptionParser.new do |o| o.on("--all") { @build_all = true } o.on("--target TARGET") { |v| @target_key = v.to_sym } end.parse!(@argv.dup) end |
#print_summary(built) ⇒ void
This method returns an undefined value.
: (Array[Hash[Symbol, untyped]]) -> void
104 105 106 107 108 109 110 111 112 |
# File 'lib/diogenes/cli/build.rb', line 104 def print_summary(built) @out.puts @out.puts "Build complete." @out.puts built.each do |b| @out.puts " #{b[:key]}:" b[:files].each { |f| @out.puts " wrote #{f}" } end end |
#run ⇒ Integer
: () -> 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 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. 1 end |
#usage_error ⇒ Integer
: () -> Integer
75 76 77 78 79 |
# File 'lib/diogenes/cli/build.rb', line 75 def usage_error @err.puts "Usage: diogenes build --all" @err.puts " diogenes build --target <target>" 1 end |