Class: Capsium::Cli::Reactor
- Inherits:
-
Thor
- Object
- Thor
- Capsium::Cli::Reactor
- Extended by:
- ThorExt::Start
- Defined in:
- lib/capsium/cli/reactor.rb
Class Method Summary collapse
-
.dispatch(meth, given_args, given_opts, config) ⇒ Object
Thor array options are last-wins when the flag repeats; collect every --mount value (both "--mount V" and "--mount=V" forms) and re-emit one trailing occurrence so repetition accumulates.
- .merge_mount_options(args) ⇒ Object
Instance Method Summary collapse
Methods included from ThorExt::Start
Class Method Details
.dispatch(meth, given_args, given_opts, config) ⇒ Object
Thor array options are last-wins when the flag repeats; collect every --mount value (both "--mount V" and "--mount=V" forms) and re-emit one trailing occurrence so repetition accumulates. (Subcommands are dispatched in-process, so this hooks dispatch, not start; merging is idempotent for the direct-start flow.)
41 42 43 44 |
# File 'lib/capsium/cli/reactor.rb', line 41 def self.dispatch(meth, given_args, given_opts, config) super(meth, (given_args), given_opts && (given_opts), config) end |
.merge_mount_options(args) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/capsium/cli/reactor.rb', line 46 def self.(args) values = [] rest = [] index = 0 while index < args.length arg = args[index] if arg == "--mount" index += 1 while index < args.length && !args[index].start_with?("-") values << args[index] index += 1 end elsif arg.start_with?("--mount=") values << arg.split("=", 2).last index += 1 else rest << arg index += 1 end end values.empty? ? args : rest + ["--mount"] + values end |
Instance Method Details
#serve(*sources) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/capsium/cli/reactor.rb', line 69 def serve(*sources) entries = mount_entries(sources) if entries.empty? raise Thor::Error, "no package source given (positional " \ "arguments, --mount or --config)" end mounts = Capsium::Reactor::Mount.build( entries, store: [:store], registry: [:registry] ) reactor = Capsium::Reactor.new( mounts: mounts, port: [:port], do_not_listen: [:do_not_listen], store: [:store], deploy: [:deploy], registry: [:registry], workdir: [:workdir] ) reactor.serve rescue Capsium::Error => e raise Thor::Error, e. ensure reactor&.cleanup end |