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