Class: OptionManager
- Inherits:
-
Object
- Object
- OptionManager
- Defined in:
- lib/mk_semi_lattice/option_manager.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize ⇒ OptionManager
constructor
A new instance of OptionManager.
- #parse! ⇒ Object
Constructor Details
#initialize ⇒ OptionManager
Returns a new instance of OptionManager.
8 9 10 |
# File 'lib/mk_semi_lattice/option_manager.rb', line 8 def initialize @options = { layer: 2, init_step: :from_semi_lattice, show_index: false, merge: false, visibility: 'normal' } end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/mk_semi_lattice/option_manager.rb', line 6 def @options end |
Instance Method Details
#parse! ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/mk_semi_lattice/option_manager.rb', line 12 def parse! a_flag = false d_flag = false OptionParser.new do |opts| opts. = <<~BANNER Usage: mk_semi_lattice PATH [options] or: hc view PATH [options] Default PATH = '.' BANNER opts.on("-L N", Integer, "Layer depth (default: 2)") do |v| @options[:layer] = v end opts.on("-n", "--node=FILE", "using File from node-edge") do |file| @options[:file] = file @options[:init_step] = :from_node_edge end opts.on("-t", "--tree=FILE", "using File from tree") do |file| @options[:file] = file @options[:init_step] = :from_tree end opts.on("-i", "--index", "Display node ids") do @options[:show_index] = true end opts.on("-l", "--log [BOOL]", "Enable/disable logging (true/false), and save to config") do |v| bool = if v.nil? true elsif v.is_a?(String) case v.strip.downcase when "true", "yes", "on", "1" true when "false", "no", "off", "0" false else puts "Invalid value for log: #{v}. Using default: false".yellow false end else !!v end Config.set_log(bool) puts "Logging is now #{bool ? 'enabled' : 'disabled'} (saved to #{Config::CONF_PATH})" exit end opts.on("-v", "--version", "show version") do puts MkSemiLattice::VERSION exit end opts.on("-d", "Show directories only") do d_flag = true end opts.on("-a", "Show all (files and directories)") do a_flag = true end opts.on("-Y", "YAML exclude mode") do @options[:visibility] = 'yaml_exclude' end =begin opts.on("-ad", "Show all directories including hidden ones") do a_flag = true d_flag = true end =end opts.on("-I PATTERN", "--ignore=PATTERN", "Ignore files/dirs matching PATTERN (e.g. '_stack_*|*.yaml')") do |pattern| # Remove leading '=' if present (e.g. when user writes -I='_stack_*|*.yaml') pattern = pattern.sub(/\A=/, '') if pattern @options[:ignore] = pattern end opts.separator " When using -I, always use '=' or quote the pattern, e.g.: -I='_stack_*|*.yaml' -a --ignore='_stack_*|*.yaml' -a Multiple patterns can be separated by '|'. Wildcards '*' and '?' are supported (like the 'tree' command). Do not use -ad; use -a -d for combined flags. " end.parse! if a_flag && d_flag @options[:visibility] = 'dir_and_hidden_dir' elsif d_flag @options[:visibility] = 'dir_only' elsif a_flag @options[:visibility] = 'all' end @options end |