command_line_helper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/Gemfile +22 -0
  2. data/LICENSE +22 -0
  3. data/README.md +70 -0
  4. data/Rakefile +23 -0
  5. data/command_line_helper.gemspec +20 -0
  6. data/lib/command_line_helper.rb +8 -0
  7. data/lib/command_line_helper.rb~ +8 -0
  8. data/lib/command_line_helper/base.rb~ +70 -0
  9. data/lib/command_line_helper/help.rb~ +67 -0
  10. data/lib/command_line_helper/help_text.rb +67 -0
  11. data/lib/command_line_helper/helper.rb~ +59 -0
  12. data/lib/command_line_helper/program_name.rb +9 -0
  13. data/lib/command_line_helper/program_name.rb~ +12 -0
  14. data/lib/command_line_helper/version.rb +3 -0
  15. data/spec/lib/command_line_helper/base_spec.rb~ +73 -0
  16. data/spec/lib/command_line_helper/help_text_spec.rb +65 -0
  17. data/spec/lib/command_line_helper/help_text_spec.rb~ +79 -0
  18. data/spec/lib/command_line_helper/helper.rb~ +23 -0
  19. data/spec/lib/command_line_helper/helper_spec.rb~ +22 -0
  20. data/spec/lib/command_line_helper/program_name_spec.rb +20 -0
  21. data/spec/lib/command_line_helper/program_name_spec.rb~ +20 -0
  22. data/spec/reports/SPEC-CommandLineHelper-Base-help-info.0.xml +11 -0
  23. data/spec/reports/SPEC-CommandLineHelper-Base-help-info.1.xml +11 -0
  24. data/spec/reports/SPEC-CommandLineHelper-Base-help-info.2.xml +11 -0
  25. data/spec/reports/SPEC-CommandLineHelper-Base-help-info.3.xml +11 -0
  26. data/spec/reports/SPEC-CommandLineHelper-Base-help-info.xml +11 -0
  27. data/spec/reports/SPEC-CommandLineHelper-Base-option-details.0.xml +9 -0
  28. data/spec/reports/SPEC-CommandLineHelper-Base-option-details.1.xml +9 -0
  29. data/spec/reports/SPEC-CommandLineHelper-Base-option-details.2.xml +9 -0
  30. data/spec/reports/SPEC-CommandLineHelper-Base-option-details.3.xml +9 -0
  31. data/spec/reports/SPEC-CommandLineHelper-Base-option-details.xml +9 -0
  32. data/spec/reports/SPEC-CommandLineHelper-Base-program-name.0.xml +13 -0
  33. data/spec/reports/SPEC-CommandLineHelper-Base-program-name.1.xml +13 -0
  34. data/spec/reports/SPEC-CommandLineHelper-Base-program-name.2.xml +13 -0
  35. data/spec/reports/SPEC-CommandLineHelper-Base-program-name.3.xml +13 -0
  36. data/spec/reports/SPEC-CommandLineHelper-Base-program-name.xml +13 -0
  37. data/spec/reports/SPEC-CommandLineHelper-Base-short-hand-option.0.xml +11 -0
  38. data/spec/reports/SPEC-CommandLineHelper-Base-short-hand-option.1.xml +11 -0
  39. data/spec/reports/SPEC-CommandLineHelper-Base-short-hand-option.2.xml +11 -0
  40. data/spec/reports/SPEC-CommandLineHelper-Base-short-hand-option.3.xml +11 -0
  41. data/spec/reports/SPEC-CommandLineHelper-Base-short-hand-option.xml +11 -0
  42. data/spec/reports/SPEC-CommandLineHelper-Base.0.xml +7 -0
  43. data/spec/reports/SPEC-CommandLineHelper-Base.1.xml +9 -0
  44. data/spec/reports/SPEC-CommandLineHelper-Base.2.xml +7 -0
  45. data/spec/reports/SPEC-CommandLineHelper-Base.3.xml +9 -0
  46. data/spec/reports/SPEC-CommandLineHelper-Base.4.xml +7 -0
  47. data/spec/reports/SPEC-CommandLineHelper-Base.5.xml +9 -0
  48. data/spec/reports/SPEC-CommandLineHelper-Base.6.xml +7 -0
  49. data/spec/reports/SPEC-CommandLineHelper-Base.7.xml +9 -0
  50. data/spec/reports/SPEC-CommandLineHelper-Base.8.xml +7 -0
  51. data/spec/reports/SPEC-CommandLineHelper-Base.xml +9 -0
  52. data/spec/reports/SPEC-CommandLineHelper-HelpText-help-info.xml +11 -0
  53. data/spec/reports/SPEC-CommandLineHelper-HelpText-option-details.xml +9 -0
  54. data/spec/reports/SPEC-CommandLineHelper-HelpText-short-hand-option.xml +11 -0
  55. data/spec/reports/SPEC-CommandLineHelper-HelpText.0.xml +7 -0
  56. data/spec/reports/SPEC-CommandLineHelper-HelpText.xml +9 -0
  57. data/spec/reports/SPEC-CommandLineHelper-ProgramName-program-name.xml +11 -0
  58. data/spec/reports/SPEC-CommandLineHelper-ProgramName.xml +7 -0
  59. data/spec/spec_helper.rb +23 -0
  60. data/spec/spec_helper.rb~ +20 -0
  61. metadata +169 -0
@@ -0,0 +1,9 @@
1
+ module CommandLineHelper
2
+ module ProgramName
3
+
4
+ def program_name
5
+ @program_name ||= File.basename($0)
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ # TODO Check for definition of options_possible
2
+ require 'active_support/concern'
3
+
4
+ module CommandLineHelper
5
+ module ProgramName
6
+
7
+ def program_name
8
+ @program_name ||= File.basename($0)
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module CommandLineHelper
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe CommandLineHelper::HelpText do
4
+ it { expect{ subject.help_info }.to raise_error }
5
+
6
+ context do
7
+ before do
8
+ subject.stub(:options_possible).and_return(
9
+ [ ['--foo', '-f', 1, 'Fooism'], ['--bar', '-b', 2, 'Bark'] ]
10
+ )
11
+ end
12
+
13
+ describe "#program_name" do
14
+ it { subject.program_name.should == "rspec" }
15
+
16
+ it {
17
+ described_class.should_receive(:program_name)
18
+ subject.program_name
19
+ }
20
+
21
+ it {
22
+ subject.program_name
23
+ described_class.instance_variable_get(:"@program_name").should == "rspec"
24
+ }
25
+ end
26
+
27
+ describe "#help_info" do
28
+ it "should return the nice string" do
29
+ subject.should_receive(:program_name)
30
+ subject.should_receive(:short_hand_options)
31
+ subject.should_receive(:option_details)
32
+ subject.should_receive(:version_info)
33
+
34
+ subject.send(:help_info)
35
+ end
36
+
37
+ it "should return helpful information based on options" do
38
+ File.stub(:basename).and_return("program_name")
39
+ subject.stub(:version_number).and_return("version")
40
+ subject.send(:help_info).should == <<-EOH
41
+ Usage: program_name [options]
42
+ [--foo|-f argument], [--bar|-b]
43
+
44
+ Options:
45
+ --foo, -f Fooism
46
+ --bar, -b Bark
47
+
48
+ 0.0.1
49
+ EOH
50
+ end
51
+ end
52
+
53
+ describe "#option_details" do
54
+ it "should return nice things" do
55
+ subject.send(:option_details).should ==
56
+ " --foo, -f Fooism\n --bar, -b Bark\n"
57
+ end
58
+ end
59
+
60
+ describe "#short_hand_option" do
61
+ it "should return '--foo|-f argument'" do
62
+ option = ["--foo", "-f", GetoptLong::REQUIRED_ARGUMENT]
63
+ subject.send(:short_hand_option, option).should == "--foo|-f argument"
64
+ end
65
+
66
+ it "should return '--bar|-b'" do
67
+ option = ["--bar", "-b", nil]
68
+ subject.send(:short_hand_option, option).should == "--bar|-b"
69
+ end
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ class HelpTextClass
4
+ include CommandLineHelper::HelpText
5
+ end
6
+
7
+ describe CommandLineHelper::HelpText do
8
+ subject { HelpTextClass.new }
9
+
10
+ it { expect{ subject.help_info }.to raise_error }
11
+
12
+ context do
13
+ before do
14
+ subject.stub(:options_possible).and_return(
15
+ [ ['--foo', '-f', 1, 'Fooism'], ['--bar', '-b', 2, 'Bark'] ]
16
+ )
17
+ end
18
+
19
+ describe "#help_info" do
20
+ it "should return the nice string" do
21
+ subject.should_receive(:program_name)
22
+ subject.should_receive(:short_hand_options)
23
+ subject.should_receive(:option_details)
24
+ subject.should_receive(:version_info)
25
+
26
+ subject.send(:help_info)
27
+ end
28
+
29
+ it "should return helpful information based on options" do
30
+ File.stub(:basename).and_return("program_name")
31
+ subject.stub(:version_number).and_return("version")
32
+ subject.send(:help_info).should == <<-EOH
33
+ Usage: program_name [options]
34
+ [--foo|-f argument], [--bar|-b]
35
+
36
+ Options:
37
+ --foo, -f Fooism
38
+ --bar, -b Bark
39
+
40
+ 0.0.1
41
+ EOH
42
+ end
43
+ end
44
+
45
+ describe "#option_details" do
46
+ it "should return nice things" do
47
+ subject.send(:option_details).should ==
48
+ " --foo, -f Fooism\n --bar, -b Bark\n"
49
+ end
50
+ end
51
+
52
+ describe "#short_hand_option" do
53
+ it "should return '--foo|-f argument'" do
54
+ option = ["--foo", "-f", GetoptLong::REQUIRED_ARGUMENT]
55
+ subject.send(:short_hand_option, option).should == "--foo|-f argument"
56
+ end
57
+
58
+ it "should return '--bar|-b'" do
59
+ option = ["--bar", "-b", nil]
60
+ subject.send(:short_hand_option, option).should == "--bar|-b"
61
+ end
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ class HelpTextClass
4
+ include CommandLineHelper::HelpText
5
+ end
6
+
7
+ describe CommandLineHelper::HelpText do
8
+ subject { HelpTextClass.new }
9
+
10
+ it { expect{ subject.help_info }.to raise_error }
11
+
12
+ context do
13
+ before do
14
+ subject.stub(:options_possible).and_return(
15
+ [ ['--foo', '-f', 1, 'Fooism'], ['--bar', '-b', 2, 'Bark'] ]
16
+ )
17
+ end
18
+
19
+ describe "#program_name" do
20
+ it { subject.program_name.should == "rspec" }
21
+
22
+ it {
23
+ described_class.should_receive(:program_name)
24
+ subject.program_name
25
+ }
26
+
27
+ it {
28
+ subject.program_name
29
+ described_class.instance_variable_get(:"@program_name").should == "rspec"
30
+ }
31
+ end
32
+
33
+ describe "#help_info" do
34
+ it "should return the nice string" do
35
+ subject.should_receive(:program_name)
36
+ subject.should_receive(:short_hand_options)
37
+ subject.should_receive(:option_details)
38
+ subject.should_receive(:version_info)
39
+
40
+ subject.send(:help_info)
41
+ end
42
+
43
+ it "should return helpful information based on options" do
44
+ File.stub(:basename).and_return("program_name")
45
+ subject.stub(:version_number).and_return("version")
46
+ subject.send(:help_info).should == <<-EOH
47
+ Usage: program_name [options]
48
+ [--foo|-f argument], [--bar|-b]
49
+
50
+ Options:
51
+ --foo, -f Fooism
52
+ --bar, -b Bark
53
+
54
+ 0.0.1
55
+ EOH
56
+ end
57
+ end
58
+
59
+ describe "#option_details" do
60
+ it "should return nice things" do
61
+ subject.send(:option_details).should ==
62
+ " --foo, -f Fooism\n --bar, -b Bark\n"
63
+ end
64
+ end
65
+
66
+ describe "#short_hand_option" do
67
+ it "should return '--foo|-f argument'" do
68
+ option = ["--foo", "-f", GetoptLong::REQUIRED_ARGUMENT]
69
+ subject.send(:short_hand_option, option).should == "--foo|-f argument"
70
+ end
71
+
72
+ it "should return '--bar|-b'" do
73
+ option = ["--bar", "-b", nil]
74
+ subject.send(:short_hand_option, option).should == "--bar|-b"
75
+ end
76
+ end
77
+
78
+ end
79
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ class CommandLineHelperHelperSpec
4
+ include CommandLineHelper::Helper
5
+
6
+ def options_possible
7
+ [ ['--blah', '-b', GetoptLong::NO_ARGUMENT, 'Helpful!' ] ]
8
+ end
9
+ end
10
+
11
+ describe CommandLineHelper::Helper do
12
+ subject { CommandLineHelperHelperSpec.new }
13
+ describe "#help_info" do
14
+ it "should return the nice string" do
15
+ subject.should_receive(:program_name)
16
+ subject.should_receive(:short_hand_options)
17
+ subject.should_receive(:option_details)
18
+ subject.should_receive(:version_info)
19
+
20
+ subject.send(:help_info)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ class CommandLineHelperHelperSpec < CommandLineHelper::Base
4
+ def options_possible
5
+ [ ['--blah', '-b', GetoptLong::NO_ARGUMENT, 'Helpful!' ] ]
6
+ end
7
+ end
8
+
9
+ describe CommandLineHelper::Helper do
10
+ subject { CommandLineHelperHelperSpec.new }
11
+
12
+ describe "#help_info" do
13
+ it "should return the nice string" do
14
+ subject.should_receive(:program_name)
15
+ subject.should_receive(:short_hand_options)
16
+ subject.should_receive(:option_details)
17
+ subject.should_receive(:version_info)
18
+
19
+ subject.send(:help_info)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ class ProgramNameClass
4
+ include CommandLineHelper::ProgramName
5
+ end
6
+
7
+ describe CommandLineHelper::ProgramName do
8
+
9
+ subject { ProgramNameClass.new }
10
+
11
+ describe "#program_name" do
12
+ it { subject.program_name.should == "rspec" }
13
+
14
+ it {
15
+ subject.program_name
16
+ subject.instance_variable_get(:"@program_name").should == "rspec"
17
+ }
18
+ end
19
+
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ class ProgramNameClass
4
+ include CommandLineHelper::ProgramName
5
+ end
6
+
7
+ describe CommandLineHelper::ProgramName do
8
+
9
+ subject { ProgramNameClass.new }
10
+
11
+ describe "#program_name" do
12
+ it { subject.program_name.should == "rspec" }
13
+
14
+ it {
15
+ subject.program_name
16
+ subject.instance_variable_get(:"@program_name").should == "rspec"
17
+ }
18
+ end
19
+
20
+ end
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="CommandLineHelper::Base#help_info" tests="2" time="0.002074" failures="0" errors="0" skipped="0">
3
+ <testcase name="CommandLineHelper::Base#help_info should return the nice string" time="0.000783">
4
+ </testcase>
5
+ <testcase name="CommandLineHelper::Base#help_info should return helpful information based on options" time="0.000998">
6
+ </testcase>
7
+ <system-out>
8
+ </system-out>
9
+ <system-err>
10
+ </system-err>
11
+ </testsuite>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="CommandLineHelper::Base#help_info" tests="2" time="0.001641" failures="0" errors="0" skipped="0">
3
+ <testcase name="CommandLineHelper::Base#help_info should return the nice string" time="0.000775">
4
+ </testcase>
5
+ <testcase name="CommandLineHelper::Base#help_info should return helpful information based on options" time="0.000666">
6
+ </testcase>
7
+ <system-out>
8
+ </system-out>
9
+ <system-err>
10
+ </system-err>
11
+ </testsuite>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="CommandLineHelper::Base#help_info" tests="2" time="0.001807" failures="0" errors="0" skipped="0">
3
+ <testcase name="CommandLineHelper::Base#help_info should return the nice string" time="0.000935">
4
+ </testcase>
5
+ <testcase name="CommandLineHelper::Base#help_info should return helpful information based on options" time="0.000665">
6
+ </testcase>
7
+ <system-out>
8
+ </system-out>
9
+ <system-err>
10
+ </system-err>
11
+ </testsuite>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="CommandLineHelper::Base#help_info" tests="2" time="0.001662" failures="0" errors="0" skipped="0">
3
+ <testcase name="CommandLineHelper::Base#help_info should return the nice string" time="0.000815">
4
+ </testcase>
5
+ <testcase name="CommandLineHelper::Base#help_info should return helpful information based on options" time="0.000634">
6
+ </testcase>
7
+ <system-out>
8
+ </system-out>
9
+ <system-err>
10
+ </system-err>
11
+ </testsuite>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="CommandLineHelper::Base#help_info" tests="2" time="0.003942" failures="0" errors="0" skipped="0">
3
+ <testcase name="CommandLineHelper::Base#help_info should return helpful information based on options" time="0.000742">
4
+ </testcase>
5
+ <testcase name="CommandLineHelper::Base#help_info should return the nice string" time="0.00076">
6
+ </testcase>
7
+ <system-out>
8
+ </system-out>
9
+ <system-err>
10
+ </system-err>
11
+ </testsuite>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="CommandLineHelper::Base#option_details" tests="1" time="0.000784" failures="0" errors="0" skipped="0">
3
+ <testcase name="CommandLineHelper::Base#option_details should return nice things" time="0.000576">
4
+ </testcase>
5
+ <system-out>
6
+ </system-out>
7
+ <system-err>
8
+ </system-err>
9
+ </testsuite>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="CommandLineHelper::Base#option_details" tests="1" time="0.002857" failures="0" errors="0" skipped="0">
3
+ <testcase name="CommandLineHelper::Base#option_details should return nice things" time="0.000512">
4
+ </testcase>
5
+ <system-out>
6
+ </system-out>
7
+ <system-err>
8
+ </system-err>
9
+ </testsuite>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="CommandLineHelper::Base#option_details" tests="1" time="0.000826" failures="0" errors="0" skipped="0">
3
+ <testcase name="CommandLineHelper::Base#option_details should return nice things" time="0.000581">
4
+ </testcase>
5
+ <system-out>
6
+ </system-out>
7
+ <system-err>
8
+ </system-err>
9
+ </testsuite>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="CommandLineHelper::Base#option_details" tests="1" time="0.000557" failures="0" errors="0" skipped="0">
3
+ <testcase name="CommandLineHelper::Base#option_details should return nice things" time="0.000398">
4
+ </testcase>
5
+ <system-out>
6
+ </system-out>
7
+ <system-err>
8
+ </system-err>
9
+ </testsuite>