From e232229812e0a1ef1108fcc44d9601897ee96384 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Fri, 13 Apr 2012 11:22:51 -0700 Subject: [PATCH] Add --rcfile (-R) option TODO: Connect option to RCFile class to set custom file path. (#19) --- lib/twurl/cli.rb | 7 +++++++ test/cli_test.rb | 13 +++++++++++++ 2 files changed, 20 insertions(+) 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