lib/bhook/args_parser.rb in bhook-0.2.2 vs lib/bhook/args_parser.rb in bhook-0.3.0
- old
+ new
@@ -3,36 +3,51 @@
module Bhook
class ArgsParser
extend T::Sig
- Options = Struct.new(:source, :output, :watch, :verbose, :theme, :generate_theme, :benchmark, :help)
+ Options = Struct.new(:source, :output, :watch, :verbose, :theme, :generate_theme, :benchmark, :mount, :help)
def initialize(argv)
- @args = Options.new(nil, nil, false, false, Bhook::THEME_DIR_PATH, nil, false, false)
+ @args = Options.new(nil, nil, false, false, Bhook::THEME_DIR_PATH, nil, false, nil, false)
@argv = argv.clone
@opt_parser = build_opt_parser
end
def parse
+ if (mount = detect_and_read_mount_args_from_config_in_pwd)
+ @args.mount = mount
+ end
+
begin
@opt_parser.parse(@argv)
- if generate_theme_missing? && help_missing? && source_or_output_paths_missing?
+ if generate_theme_missing? && help_missing? &&
+ source_or_output_paths_missing? && mount_config_missing?
raise OptionParser::MissingArgument, 'See --help.'
end
rescue OptionParser::ParseError => e
puts "\nError! #{e.message}\n"
return nil
end
-
@args
end
def help_text
@opt_parser.to_s
end
private
+
+ def detect_and_read_mount_args_from_config_in_pwd
+ bhook_config_path = File.join(Dir.pwd, Config::BHOOK_CONFIG_FILE)
+ return unless File.exist?(bhook_config_path)
+
+ YAML.safe_load(File.read(bhook_config_path))['mount']
+ end
+
+ def mount_config_missing?
+ !@args.mount
+ end
def help_missing?
!@args.help
end