diff --git a/lib/twurl/cli.rb b/lib/twurl/cli.rb index 4f422e1..12329a0 100644 --- a/lib/twurl/cli.rb +++ b/lib/twurl/cli.rb @@ -70,6 +70,7 @@ def parse_options(args) quiet disable_ssl request_method + rcfile help version end @@ -232,6 +233,12 @@ def request_method end end + def rcfile + on('-R', '--rcfile [path]', 'Path to RC file (default: ~/.twurlrc)') do |rcfile| + options.rcfile = rcfile + end + end + def help on_tail("-h", "--help", "Show this message") do CLI.puts self diff --git a/test/cli_test.rb b/test/cli_test.rb index ac5e0ce..460eac3 100644 --- a/test/cli_test.rb +++ b/test/cli_test.rb @@ -150,4 +150,17 @@ def test_setting_host_updates_to_requested_value end end include HostOptionTests + + module RCFileTests + def test_setting_rcfile_uses_custom_rcfile + custom_rcfile = '/tmp/rcfile' + assert Twurl::RCFile.file_path != custom_rcfile + + [['-R', custom_rcfile], ['--rcfile', custom_rcfile]].each do |option_combination| + options = Twurl::CLI.parse_options(option_combination) + assert_equal custom_rcfile, options.rcfile + end + end + end + include RCFileTests end