Module: Rubycli
- Defined in:
- lib/rubycli.rb,
lib/rubycli/cli.rb,
lib/rubycli/types.rb,
lib/rubycli/runner.rb,
lib/rubycli/version.rb,
lib/rubycli/type_utils.rb,
lib/rubycli/environment.rb,
lib/rubycli/command_line.rb,
lib/rubycli/eval_coercer.rb,
lib/rubycli/json_coercer.rb,
lib/rubycli/help_renderer.rb,
lib/rubycli/result_emitter.rb,
lib/rubycli/argument_parser.rb,
lib/rubycli/constant_capture.rb,
lib/rubycli/arguments/token_stream.rb,
lib/rubycli/documentation_registry.rb,
lib/rubycli/argument_mode_controller.rb,
lib/rubycli/arguments/value_converter.rb,
lib/rubycli/documentation/metadata_parser.rb,
lib/rubycli/documentation/comment_extractor.rb
Defined Under Namespace
Modules: Arguments, CommandLine, Documentation, Runner, TypeUtils
Classes: ArgumentError, ArgumentModeController, ArgumentParser, CLI, CommandNotFoundError, ConstantCapture, DocumentationRegistry, Environment, Error, EvalCoercer, HelpRenderer, JsonCoercer, OptionDefinition, PositionalDefinition, ResultEmitter, ReturnDefinition
Constant Summary
collapse
- VERSION =
'0.2.0'
Class Method Summary
collapse
-
.apply_argument_coercions(pos_args, kw_args) ⇒ Object
-
.apply_json_coercion(pos_args, kw_args) ⇒ Object
-
.argument_mode_controller ⇒ Object
-
.argument_parser ⇒ Object
-
.available_commands(target) ⇒ Object
-
.call_target(target_callable, pos_args, kw_args) ⇒ Object
-
.cli ⇒ Object
-
.coerce_eval_value(value) ⇒ Object
-
.coerce_json_value(value) ⇒ Object
-
.constant_capture ⇒ Object
-
.debug_log(message) ⇒ Object
-
.documentation_registry ⇒ Object
-
.environment ⇒ Object
-
.eval_coercer ⇒ Object
-
.eval_lax_mode? ⇒ Boolean
-
.eval_mode? ⇒ Boolean
-
.find_method(target, command) ⇒ Object
-
.help_renderer ⇒ Object
-
.json_coercer ⇒ Object
-
.json_mode? ⇒ Boolean
-
.method_description(method) ⇒ Object
-
.parse_arguments(args, method = nil) ⇒ Object
-
.print_help(target) ⇒ Object
-
.result_emitter ⇒ Object
-
.run(target, args = ARGV, cli_mode = true) ⇒ Object
-
.usage_for_method(command, method) ⇒ Object
-
.with_eval_mode(enabled = true, **options, &block) ⇒ Object
-
.with_json_mode(enabled = true, &block) ⇒ Object
Class Method Details
.apply_argument_coercions(pos_args, kw_args) ⇒ Object
151
152
153
|
# File 'lib/rubycli.rb', line 151
def apply_argument_coercions(pos_args, kw_args)
argument_mode_controller.apply_argument_coercions(pos_args, kw_args)
end
|
.apply_json_coercion(pos_args, kw_args) ⇒ Object
155
156
157
|
# File 'lib/rubycli.rb', line 155
def apply_json_coercion(pos_args, kw_args)
apply_argument_coercions(pos_args, kw_args)
end
|
.argument_mode_controller ⇒ Object
44
45
46
47
48
49
|
# File 'lib/rubycli.rb', line 44
def argument_mode_controller
@argument_mode_controller ||= ArgumentModeController.new(
json_coercer: json_coercer,
eval_coercer: eval_coercer
)
end
|
.argument_parser ⇒ Object
51
52
53
54
55
56
57
58
|
# File 'lib/rubycli.rb', line 51
def argument_parser
@argument_parser ||= ArgumentParser.new(
environment: environment,
documentation_registry: documentation_registry,
json_coercer: json_coercer,
debug_logger: method(:debug_log)
)
end
|
.available_commands(target) ⇒ Object
93
94
95
|
# File 'lib/rubycli.rb', line 93
def available_commands(target)
cli.available_commands(target)
end
|
.call_target(target_callable, pos_args, kw_args) ⇒ Object
114
115
116
117
|
# File 'lib/rubycli.rb', line 114
def call_target(target_callable, pos_args, kw_args)
debug_log "Calling target with pos_args: #{pos_args.inspect}, kw_args: #{kw_args.inspect}"
kw_args.empty? ? target_callable.call(*pos_args) : target_callable.call(*pos_args, **kw_args)
end
|
.cli ⇒ Object
72
73
74
75
76
77
78
79
80
|
# File 'lib/rubycli.rb', line 72
def cli
@cli ||= CLI.new(
environment: environment,
argument_parser: argument_parser,
documentation_registry: documentation_registry,
help_renderer: help_renderer,
result_emitter: result_emitter
)
end
|
.coerce_eval_value(value) ⇒ Object
147
148
149
|
# File 'lib/rubycli.rb', line 147
def coerce_eval_value(value)
eval_coercer.coerce_eval_value(value)
end
|
.coerce_json_value(value) ⇒ Object
131
132
133
|
# File 'lib/rubycli.rb', line 131
def coerce_json_value(value)
json_coercer.coerce_json_value(value)
end
|
.constant_capture ⇒ Object
68
69
70
|
# File 'lib/rubycli.rb', line 68
def constant_capture
@constant_capture ||= ConstantCapture.new
end
|
.debug_log(message) ⇒ Object
119
120
121
|
# File 'lib/rubycli.rb', line 119
def debug_log(message)
puts "[DEBUG] #{message}" if environment.debug?
end
|
.documentation_registry ⇒ Object
32
33
34
|
# File 'lib/rubycli.rb', line 32
def documentation_registry
@documentation_registry ||= DocumentationRegistry.new(environment: environment)
end
|
.environment ⇒ Object
28
29
30
|
# File 'lib/rubycli.rb', line 28
def environment
@environment ||= Environment.new(env: ENV, argv: ARGV)
end
|
.eval_coercer ⇒ Object
40
41
42
|
# File 'lib/rubycli.rb', line 40
def eval_coercer
@eval_coercer ||= EvalCoercer.new
end
|
.eval_lax_mode? ⇒ Boolean
139
140
141
|
# File 'lib/rubycli.rb', line 139
def eval_lax_mode?
eval_coercer.eval_lax_mode?
end
|
.eval_mode? ⇒ Boolean
135
136
137
|
# File 'lib/rubycli.rb', line 135
def eval_mode?
argument_mode_controller.eval_mode?
end
|
.find_method(target, command) ⇒ Object
97
98
99
|
# File 'lib/rubycli.rb', line 97
def find_method(target, command)
cli.find_method(target, command)
end
|
.help_renderer ⇒ Object
60
61
62
|
# File 'lib/rubycli.rb', line 60
def help_renderer
@help_renderer ||= HelpRenderer.new(documentation_registry: documentation_registry)
end
|
.json_coercer ⇒ Object
36
37
38
|
# File 'lib/rubycli.rb', line 36
def json_coercer
@json_coercer ||= JsonCoercer.new
end
|
.json_mode? ⇒ Boolean
123
124
125
|
# File 'lib/rubycli.rb', line 123
def json_mode?
argument_mode_controller.json_mode?
end
|
.method_description(method) ⇒ Object
105
106
107
|
# File 'lib/rubycli.rb', line 105
def method_description(method)
cli.method_description(method)
end
|
.parse_arguments(args, method = nil) ⇒ Object
89
90
91
|
# File 'lib/rubycli.rb', line 89
def parse_arguments(args, method = nil)
argument_parser.parse(args.dup, method)
end
|
.print_help(target) ⇒ Object
109
110
111
112
|
# File 'lib/rubycli.rb', line 109
def print_help(target)
catalog = cli.command_catalog_for(target)
help_renderer.print_help(target, catalog)
end
|
.result_emitter ⇒ Object
64
65
66
|
# File 'lib/rubycli.rb', line 64
def result_emitter
@result_emitter ||= ResultEmitter.new(environment: environment)
end
|
.run(target, args = ARGV, cli_mode = true) ⇒ Object
82
83
84
85
86
87
|
# File 'lib/rubycli.rb', line 82
def run(target, args = ARGV, cli_mode = true)
status = cli.run(target, args.dup, cli_mode)
return status unless cli_mode
exit(status.to_i)
end
|
.usage_for_method(command, method) ⇒ Object
101
102
103
|
# File 'lib/rubycli.rb', line 101
def usage_for_method(command, method)
cli.usage_for_method(command, method)
end
|
.with_eval_mode(enabled = true, **options, &block) ⇒ Object
143
144
145
|
# File 'lib/rubycli.rb', line 143
def with_eval_mode(enabled = true, **options, &block)
argument_mode_controller.with_eval_mode(enabled, **options, &block)
end
|
.with_json_mode(enabled = true, &block) ⇒ Object
127
128
129
|
# File 'lib/rubycli.rb', line 127
def with_json_mode(enabled = true, &block)
argument_mode_controller.with_json_mode(enabled, &block)
end
|