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
#completion_data
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, #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
7
8
9
10
11
12
|
# File 'lib/bashly/script/flag.rb', line 7
def option_keys
@option_keys ||= %i[
allowed arg completions conflicts default help long repeatable
required short unique validate private
]
end
|
Instance Method Details
#aliases ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/bashly/script/flag.rb', line 15
def aliases
if long && short
[long, short]
elsif long
[long]
else
[short]
end
end
|
#default_string ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/bashly/script/flag.rb', line 25
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
35
36
37
|
# File 'lib/bashly/script/flag.rb', line 35
def name
long || short
end
|
#usage_string(extended: false) ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/bashly/script/flag.rb', line 39
def usage_string(extended: false)
result = [aliases.join(', ')]
result << arg.upcase if arg
result << strings[:required] if required && extended
result << strings[:repeatable] if repeatable && extended
result.join ' '
end
|