very simple option validation
This commit is contained in:
parent
9ee433eb2b
commit
24a2479a97
|
@ -7,8 +7,15 @@ require "../../tmux"
|
|||
class Fingers::Commands::LoadConfig < Fingers::Commands::Base
|
||||
@fingers_options_names : Array(String) | Nil
|
||||
|
||||
property config : Fingers::Config
|
||||
|
||||
DISALLOWED_CHARS = /cimqn/
|
||||
|
||||
def initialize(*args)
|
||||
super(*args)
|
||||
@config = Fingers::Config.new
|
||||
end
|
||||
|
||||
def run
|
||||
validate_options!
|
||||
parse_tmux_conf
|
||||
|
@ -24,8 +31,6 @@ class Fingers::Commands::LoadConfig < Fingers::Commands::Base
|
|||
|
||||
Fingers.reset_config
|
||||
|
||||
config = Fingers::Config.new
|
||||
|
||||
config.tmux_version = `tmux -V`.chomp.split(" ").last
|
||||
|
||||
options.each do |option, value|
|
||||
|
@ -58,6 +63,7 @@ class Fingers::Commands::LoadConfig < Fingers::Commands::Base
|
|||
end
|
||||
|
||||
if option.match(/pattern/)
|
||||
check_pattern!(value)
|
||||
user_defined_patterns.push(value)
|
||||
end
|
||||
end
|
||||
|
@ -132,8 +138,7 @@ class Fingers::Commands::LoadConfig < Fingers::Commands::Base
|
|||
def valid_option?(option)
|
||||
option_method = option_to_method(option)
|
||||
|
||||
# TODO validate option
|
||||
true
|
||||
@config.members.includes?(option_method) || option_method.match(/pattern_[0-9]+/) || option_method == "skip_wizard"
|
||||
end
|
||||
|
||||
def fingers_options_names
|
||||
|
@ -144,6 +149,16 @@ class Fingers::Commands::LoadConfig < Fingers::Commands::Base
|
|||
`tmux set-option -ug #{option}`
|
||||
end
|
||||
|
||||
def check_pattern!(pattern)
|
||||
begin
|
||||
Regex.new(pattern)
|
||||
rescue e: ArgumentError
|
||||
puts "[tmux-fingers] Invalid pattern: #{pattern}"
|
||||
puts "[tmux-fingers] #{e.message}"
|
||||
exit(1)
|
||||
end
|
||||
end
|
||||
|
||||
def validate_options!
|
||||
errors = [] of String
|
||||
|
||||
|
|
|
@ -87,6 +87,10 @@ module Fingers
|
|||
def save
|
||||
to_json(File.open(::Fingers::Dirs::CONFIG_PATH, "w"))
|
||||
end
|
||||
|
||||
def members : Array(String)
|
||||
JSON.parse(to_json).as_h.keys
|
||||
end
|
||||
end
|
||||
|
||||
def self.config
|
||||
|
|
Loading…
Reference in New Issue