Class: Bashly::Script::Flag
Instance Attribute Summary
Attributes inherited from Base
#options
Attributes included from Renderable
#render_options
Class Method Summary
collapse
Instance Method Summary
collapse
#validate, #validate?
#visibility
#completion_data, #completion_option_entry
Methods inherited from Base
#help, #initialize, #method_missing, #optional, #respond_to_missing?, #summary
Methods included from Renderable
#load_user_file, #render, #strings, #user_file_exist?, #user_file_path, #user_string, #view_marker
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Bashly::Script::Base
Class Method Details
.option_keys ⇒ Object
11
12
13
14
15
16
|
# File 'lib/bashly/script/flag.rb', line 11
def option_keys
@option_keys ||= %i[
alias allowed arg completions conflicts default help long needs
negatable private repeatable required short unique validate
]
end
|
Instance Method Details
#aliases ⇒ Object
25
26
27
|
# File 'lib/bashly/script/flag.rb', line 25
def aliases
[long, negated_long, short].compact + alt
end
|
#alt ⇒ Object
19
20
21
22
23
|
# File 'lib/bashly/script/flag.rb', line 19
def alt
return [] unless options['alias']
options['alias'].is_a?(String) ? [options['alias']] : options['alias']
end
|
#default_string ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/bashly/script/flag.rb', line 37
def default_string
if default.is_a?(Array)
Shellwords.shelljoin default
elsif default.is_a?(String) && repeatable
Shellwords.shellescape default
else
default
end
end
|
#name ⇒ Object
47
48
49
|
# File 'lib/bashly/script/flag.rb', line 47
def name
long || short
end
|
#negated_long ⇒ Object
33
34
35
|
# File 'lib/bashly/script/flag.rb', line 33
def negated_long
"--no-#{long_without_prefix}" if negatable && long
end
|
#positive_aliases ⇒ Object
29
30
31
|
# File 'lib/bashly/script/flag.rb', line 29
def positive_aliases
primary_aliases + alt
end
|
#usage_string(extended: false) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/bashly/script/flag.rb', line 51
def usage_string(extended: false)
result = [usage_aliases.join(', ')]
result << arg.upcase if arg
result << strings[:required] if required && extended
result << strings[:repeatable] if repeatable && extended
result.join ' '
end
|