Class: Bashly::Script::Argument

Inherits:
Base
  • Object
show all
Defined in:
lib/bashly/script/argument.rb

Instance Attribute Summary

Attributes inherited from Base

#options

Attributes included from Renderable

#render_options

Class Method Summary collapse

Instance Method Summary collapse

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

Constructor Details

This class inherits a constructor from Bashly::Script::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Bashly::Script::Base

Class Method Details

.option_keysObject



7
8
9
10
11
# File 'lib/bashly/script/argument.rb', line 7

def option_keys
  @option_keys ||= %i[
    allowed default help name repeatable required unique validate
  ]
end

Instance Method Details

#default_stringObject



14
15
16
17
18
19
20
21
22
# File 'lib/bashly/script/argument.rb', line 14

def default_string
  if default.is_a?(Array)
    Shellwords.shelljoin default
  elsif default.is_a?(String) && repeatable
    Shellwords.shellescape default
  else
    default
  end
end

#labelObject



28
29
30
# File 'lib/bashly/script/argument.rb', line 28

def label
  repeatable ? "#{name.upcase}..." : name.upcase
end

#usage_stringObject



24
25
26
# File 'lib/bashly/script/argument.rb', line 24

def usage_string
  required ? label : "[#{label}]"
end