gitnesse 0.12.6 → 1.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +6 -0
  3. data/Rakefile +6 -11
  4. data/bin/.keep +0 -0
  5. data/bin/gitnesse +2 -32
  6. data/config/gitnesse.rb.example +2 -4
  7. data/gitnesse.gemspec +22 -21
  8. data/lib/gitnesse/cli/helpers/config_helpers.rb +13 -0
  9. data/lib/gitnesse/cli/helpers/feature_helpers.rb +26 -0
  10. data/lib/gitnesse/cli/helpers/wiki_helpers.rb +53 -0
  11. data/lib/gitnesse/cli/task/help.rb +42 -0
  12. data/lib/gitnesse/cli/task/info.rb +29 -0
  13. data/lib/gitnesse/cli/task/pull.rb +26 -0
  14. data/lib/gitnesse/cli/task/push.rb +101 -0
  15. data/lib/gitnesse/cli/task/run.rb +85 -0
  16. data/lib/gitnesse/cli/task.rb +67 -0
  17. data/lib/gitnesse/cli.rb +55 -0
  18. data/lib/gitnesse/config.rb +68 -0
  19. data/lib/gitnesse/config_loader.rb +36 -0
  20. data/lib/gitnesse/dependency_checker.rb +86 -0
  21. data/lib/gitnesse/dir_manager.rb +37 -0
  22. data/lib/gitnesse/feature.rb +63 -0
  23. data/lib/gitnesse/feature_extractor.rb +29 -0
  24. data/lib/gitnesse/feature_transform.rb +30 -0
  25. data/lib/gitnesse/hooks/gitnesse.rb +5 -0
  26. data/lib/gitnesse/hooks.rb +30 -33
  27. data/lib/gitnesse/railtie.rb +3 -1
  28. data/lib/gitnesse/rake/tasks.rake +11 -0
  29. data/lib/gitnesse/tasks.rb +7 -4
  30. data/lib/gitnesse/version.rb +1 -1
  31. data/lib/gitnesse/wiki/page.rb +103 -0
  32. data/lib/gitnesse/wiki.rb +80 -143
  33. data/lib/gitnesse.rb +10 -102
  34. data/spec/lib/cli/task/help_spec.rb +34 -0
  35. data/spec/lib/cli/task/info_spec.rb +22 -0
  36. data/spec/lib/cli/task/pull_spec.rb +24 -0
  37. data/spec/lib/cli/task/push_spec.rb +24 -0
  38. data/spec/lib/cli_spec.rb +13 -0
  39. data/spec/lib/config_loader_spec.rb +46 -0
  40. data/spec/lib/config_spec.rb +61 -0
  41. data/spec/lib/dependency_checker_spec.rb +193 -0
  42. data/spec/lib/dir_manager_spec.rb +46 -0
  43. data/spec/lib/feature_extractor_spec.rb +30 -0
  44. data/spec/lib/feature_spec.rb +53 -0
  45. data/spec/lib/feature_transform_spec.rb +25 -0
  46. data/spec/lib/hooks_spec.rb +40 -0
  47. data/spec/lib/version_spec.rb +9 -0
  48. data/spec/lib/wiki/page_spec.rb +68 -0
  49. data/spec/lib/wiki_spec.rb +34 -0
  50. data/spec/spec_helper.rb +4 -0
  51. data/spec/support/cli.rb +20 -0
  52. data/spec/support/example_config/gitnesse.rb +4 -0
  53. data/{test/test_helper.rb → spec/support/example_features/addition.feature} +0 -16
  54. data/spec/support/example_features/division.feature +10 -0
  55. data/spec/support/example_wiki_pages/developer_can_sync_features_to_code.md +29 -0
  56. data/spec/support_helper.rb +79 -0
  57. metadata +103 -109
  58. data/README.md +0 -85
  59. data/features/step_definitions/gitnesse_steps.rb +0 -54
  60. data/features/support/env.rb +0 -65
  61. data/features/sync_wiki_features_to_code.feature +0 -29
  62. data/lib/gitnesse/configuration.rb +0 -54
  63. data/lib/gitnesse/dependencies.rb +0 -39
  64. data/lib/gitnesse/features.rb +0 -38
  65. data/lib/gitnesse/git_config.rb +0 -39
  66. data/lib/gitnesse/support/hook.rb +0 -11
  67. data/lib/gitnesse/tasks.rake +0 -34
  68. data/test/lib/gitnesse/build_page_content_test.rb +0 -89
  69. data/test/lib/gitnesse/commit_info_test.rb +0 -16
  70. data/test/lib/gitnesse/configuration_defaults_test.rb +0 -11
  71. data/test/lib/gitnesse/configuration_to_hash_test.rb +0 -25
  72. data/test/lib/gitnesse/custom_branch_test.rb +0 -24
  73. data/test/lib/gitnesse/dependencies_check_test.rb +0 -73
  74. data/test/lib/gitnesse/extract_features_test.rb +0 -44
  75. data/test/lib/gitnesse/gather_test.rb +0 -30
  76. data/test/lib/gitnesse/load_feature_files_into_wiki_test.rb +0 -34
  77. data/test/lib/gitnesse/read_git_config_test.rb +0 -33
  78. data/test/lib/gitnesse/strip_results_test.rb +0 -52
  79. data/test/lib/gitnesse/version_test.rb +0 -7
  80. data/test/lib/gitnesse/wiki_append_results_test.rb +0 -50
  81. data/test/lib/gitnesse/write_file_test.rb +0 -18
  82. data/test/wiki_test_helper.rb +0 -11
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 319d9cc7127178d8e7fe987e28efec8c6229cfbe
4
+ data.tar.gz: 5568348a2109c7078ccfbd832b8957a7e96fdf0e
5
+ SHA512:
6
+ metadata.gz: c6f71b9db9c3e09715e2a02f69a4a5b16fbdac250a620de68baf57251606363d0ef95e354e29c83200f2c064aecbd6a1a274185ea5b6b465100617551fb2c1c3
7
+ data.tar.gz: 080d0b3968b3ba38af8d3535d246c09f31d1ba5755584b792c6fb190f191e9b8e5c02d80ebae2321b10b89731332d34909da029c3e2b37aa45af4c7c7df745b1
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-19mode
6
+ - rbx-19mode
data/Rakefile CHANGED
@@ -1,13 +1,8 @@
1
- #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
3
- require 'rake/testtask'
4
- require_relative 'lib/gitnesse'
5
- require_relative 'lib/gitnesse/tasks'
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
6
3
 
7
- Rake::TestTask.new do |t|
8
- t.libs << 'lib/gitnesse'
9
- t.test_files = FileList['test/lib/gitnesse/*_test.rb']
10
- t.verbose = true
11
- end
12
- task :default => :test
4
+ Bundler::GemHelper.install_tasks
13
5
 
6
+ task default: :spec
7
+
8
+ RSpec::Core::RakeTask.new :spec
data/bin/.keep ADDED
File without changes
data/bin/gitnesse CHANGED
@@ -1,35 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'rubygems'
4
- require 'gitnesse'
3
+ require 'gitnesse/cli'
5
4
 
6
- Gitnesse::Configuration.load_using_search
7
-
8
- if ARGV[0].nil?
9
- Gitnesse.run
10
- end
11
-
12
- def print_help
13
- puts "Gitnesse commands:"
14
- puts " run: pull remote features from git-based wiki to local, and run Cucumber"
15
- puts " push: push local features to git-based wiki"
16
- puts " pull: pull remote features from git-based wiki to local"
17
- puts " info: print current Gitnesse configuration"
18
- end
19
-
20
- case ARGV[0]
21
- when "push"
22
- Gitnesse.push
23
- when "pull"
24
- Gitnesse.pull
25
- when "run"
26
- Gitnesse.run
27
- when "info"
28
- puts Gitnesse.configuration.to_yaml
29
- when "push_results"
30
- Gitnesse.push_results
31
- when "help"
32
- print_help
33
- else
34
- print_help
35
- end
5
+ Gitnesse::Cli.new.parse
@@ -1,5 +1,3 @@
1
- Gitnesse.configure do |config|
2
- config.repository_url = "git@github.com:hybridgroup/gitnesse.wiki.git"
3
- config.annotate_results = true
4
- config.info = "Bob Martin's development laptop"
1
+ Gitnesse::Config.config do |c|
2
+ c.repository_url = "https://github.com/hybridgroup/gitnesse.wiki.git"
5
3
  end
data/gitnesse.gemspec CHANGED
@@ -1,25 +1,26 @@
1
1
  # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'gitnesse/version'
2
+ require File.expand_path '../lib/gitnesse/version', __FILE__
5
3
 
6
- Gem::Specification.new do |gem|
7
- gem.name = "gitnesse"
8
- gem.version = Gitnesse::VERSION
9
- gem.authors = ["www.hybridgroup.com"]
10
- gem.email = ["info@hybridgroup.com"]
11
- gem.description = %q{Use github wiki to store feature stories, then execute then using Cucumber}
12
- gem.summary = %q{Features on git-based Wiki!}
13
- gem.homepage = "https://github.com/hybridgroup/gitnesse"
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "gitnesse"
6
+ spec.version = Gitnesse::VERSION
7
+ spec.authors = ["www.hybridgroup.com"]
8
+ spec.email = ["info@hybridgroup.com"]
9
+ spec.description = %q{Gitnesse lets you sync Cucumber feature stories
10
+ through a Git-based wiki, and display current
11
+ scenario results on wiki pages}
12
+ spec.summary = %q{Sync your feature stories using a Git-based wiki!}
13
+ spec.homepage = "https://github.com/hybridgroup/gitnesse"
14
+ spec.license = "MIT"
14
15
 
15
- gem.files = `git ls-files`.split($/)
16
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
- gem.require_paths = ["lib"]
18
- gem.add_dependency("bundler")
19
- gem.add_dependency("gollum","~> 2.3.12")
20
- gem.add_development_dependency("minitest-matchers")
21
- gem.add_development_dependency("mocha")
22
- gem.add_development_dependency("cucumber")
23
- gem.add_development_dependency("rake")
24
- gem.executables = ['gitnesse']
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "bundler", "~> 1.3"
22
+ spec.add_dependency "git", "~> 1.2.6"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec", "~> 2.14.1"
25
+ spec.add_development_dependency "cucumber", "~> 1.3.4"
25
26
  end
@@ -0,0 +1,13 @@
1
+ module Gitnesse
2
+ class Cli
3
+ module ConfigHelpers
4
+ # Loads and checks Gitnesse configuration/dependencies
5
+ #
6
+ # Returns an instance of Gitnesse::Config
7
+ def load_and_check_config
8
+ Gitnesse::ConfigLoader.find_and_load
9
+ Gitnesse::DependencyChecker.new.check
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ module Gitnesse
2
+ class Cli
3
+ module FeatureHelpers
4
+ # Public: Creates or updates local cucumber features
5
+ #
6
+ # Returns nothing.
7
+ def create_or_update_local_features
8
+ puts " Creating and updating local features."
9
+
10
+ @feature_pages.each do |page|
11
+ if File.exists?(page.path)
12
+ puts " - Updating #{page.path}"
13
+ else
14
+ puts " - Creating #{page.path}"
15
+ FileUtils.mkdir_p page.relative_path
16
+ end
17
+
18
+ feature = Gitnesse::Feature.new(page.path)
19
+ features = Gitnesse::FeatureExtractor.extract!(page.read)
20
+
21
+ feature.write(features.join("\n\n"))
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,53 @@
1
+ module Gitnesse
2
+ class Cli
3
+ module WikiHelpers
4
+ # Public: Clones or updates local copy of remote git-based wiki. Also prints
5
+ # message indicating which operation is taking place
6
+ #
7
+ # Returns instance of Gitnesse::Wiki referring to new/updated local wiki
8
+ def clone_wiki
9
+ opts = {}
10
+ @dir = Gitnesse::DirManager.project_dir
11
+
12
+ unless Gitnesse::DirManager.project_dir_present?
13
+ Gitnesse::DirManager.make_project_dir
14
+ end
15
+
16
+ @wiki = Gitnesse::Wiki.new @config.repository_url, @dir
17
+ end
18
+
19
+ # Public: Removes existing features from local copy of remote wiki.
20
+ #
21
+ # Returns nothing.
22
+ def remove_existing_features
23
+ @wiki.remove_features
24
+ end
25
+
26
+ # Public: Commits wiki changes, and pushes changes to remote wiki.
27
+ #
28
+ # Returns nothing.
29
+ def commit_and_push_changes
30
+ puts " Commiting changes."
31
+ @wiki.commit
32
+
33
+ puts " Pushing changes to remote wiki."
34
+ @wiki.push
35
+ end
36
+
37
+ # Public: Extracts wiki pages that contain cucumber features.
38
+ #
39
+ # Returns an array of wiki pages containing features
40
+ def extract_features_from_wiki
41
+ unless @wiki.pages.any?
42
+ abort " Wiki contains no features."
43
+ end
44
+
45
+ puts " Extracting wiki pages containing features."
46
+
47
+ @feature_pages = @wiki.pages.select do |page|
48
+ Gitnesse::FeatureExtractor.contains_features? page.read
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,42 @@
1
+ Gitnesse::Cli.task :help, nil do
2
+ def perform(name = nil)
3
+ return overview unless name
4
+
5
+ task = tasks_by_name[name]
6
+ abort "No help for task '#{name}'" unless task && task.help
7
+
8
+ puts task.help
9
+ end
10
+
11
+ private
12
+ def overview
13
+ puts <<-EOS
14
+ USAGE: gitnesse <task> [<args>]
15
+
16
+ The gitnesse tasks are:
17
+ EOS
18
+
19
+ tasks_to_show do |name, desc|
20
+ puts " #{name} #{desc}"
21
+ end
22
+
23
+ puts ''
24
+ puts "See 'gitnesse help <task>' for more information on a specific task."
25
+ end
26
+
27
+ def tasks_by_name
28
+ Gitnesse::Cli.tasks
29
+ end
30
+
31
+ def tasks
32
+ tasks_by_name.values.uniq
33
+ end
34
+
35
+ def tasks_to_show
36
+ size = tasks.map { |t| t.name.length }.max
37
+ tasks.sort_by(&:name).each do |task|
38
+ next unless task.desc
39
+ yield task.name.ljust(size), task.desc
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,29 @@
1
+ Gitnesse::Cli.task :info do
2
+ desc "Prints current Gitnesse configuration"
3
+
4
+ def perform
5
+ Gitnesse::ConfigLoader.find_and_load
6
+ config = Gitnesse::Config.instance.to_h
7
+ size = config.keys.map(&:length).max
8
+
9
+ puts "Current Gitnesse Configuration:"
10
+
11
+ config.each do |key, value|
12
+ puts " #{key.to_s.rjust(size)} - #{value || "[not set]"}"
13
+ end
14
+ end
15
+
16
+ help do
17
+ <<-EOS
18
+ USAGE: gitnesse info
19
+
20
+ #{desc}
21
+
22
+ Prints the current Gitnesse configuration settings, including settings loaded
23
+ from gitnesse.rb configuration files.
24
+
25
+ Examples:
26
+ gitnesse list # will print current configuration
27
+ EOS
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ Gitnesse::Cli.task :pull do
2
+ desc "Pulls features from remote git-based wiki"
3
+
4
+ help do
5
+ <<-EOS
6
+ USAGE: gitnesse pull
7
+
8
+ #{desc}
9
+
10
+ Pulls the remote wiki, finds the feature files it contains, and updates the
11
+ relevant local features, creating new ones if necessary.
12
+
13
+ Examples:
14
+ gitnesse pull # will pull features from remote wiki
15
+ EOS
16
+ end
17
+
18
+ def perform
19
+ load_and_check_config
20
+ clone_wiki
21
+ extract_features_from_wiki
22
+ create_or_update_local_features
23
+
24
+ puts " Done."
25
+ end
26
+ end
@@ -0,0 +1,101 @@
1
+ Gitnesse::Cli.task :push do
2
+ desc "Pushes local features to remote git-based wiki"
3
+
4
+ help do
5
+ <<-EOS
6
+ USAGE: gitnesse push
7
+
8
+ #{desc}
9
+
10
+ Pushes the local features files to the remote git-based wiki, creating/updating
11
+ wiki pages as necessary.
12
+
13
+ Examples:
14
+ gitnesse push # will push local features to remote wiki
15
+ EOS
16
+ end
17
+
18
+ def perform
19
+ load_and_check_config
20
+ clone_wiki
21
+ remove_existing_features
22
+ collect_features
23
+ add_index_page
24
+ add_feature_index_pages_to_wiki
25
+ add_features_to_wiki
26
+ commit_and_push_changes
27
+
28
+ puts " Done."
29
+ end
30
+
31
+ private
32
+ def collect_features
33
+ puts " Collecting local features."
34
+ Dir.chdir @config.features_dir do
35
+ @features = Dir.glob("**/*.feature").each_with_object([]) do |f, a|
36
+ a << Gitnesse::Feature.new(f)
37
+ end
38
+ end
39
+
40
+ unless @features.any?
41
+ abort " No local features found."
42
+ end
43
+ end
44
+
45
+ def add_feature_index_pages_to_wiki
46
+ nested = @features.group_by(&:index_page)
47
+ nested.reject! { |k,v| k == 'features.md' }
48
+
49
+ if nested.any?
50
+ puts " Creating index pages:"
51
+ end
52
+
53
+ nested.each do |filename, features|
54
+ content = features.each_with_object("") do |f, s|
55
+ s << "- #{f.relative_link}\n"
56
+ end
57
+
58
+ puts " - #{filename}"
59
+
60
+ @wiki.add_page(filename, content)
61
+ end
62
+ end
63
+
64
+ def add_features_to_wiki
65
+ puts " Creating/updating wiki features:"
66
+ @features.each do |feature|
67
+ puts " - #{feature.wiki_filename}"
68
+
69
+ filename = feature.wiki_filename
70
+ content = Gitnesse::FeatureTransform.convert(feature.read)
71
+ @wiki.add_page(filename, content)
72
+ end
73
+ end
74
+
75
+ def add_index_page
76
+ filename = "features.md"
77
+ content = "# Features\n\n"
78
+
79
+ puts " Creating index page: #{filename}"
80
+
81
+ nested = @features.group_by(&:index_page)
82
+
83
+ if nested.key?("features.md") && nested["features.md"].any?
84
+ features = nested.delete("features.md")
85
+
86
+ features.each do |f|
87
+ content << "- #{f.relative_link}\n"
88
+ end
89
+ end
90
+
91
+ nested.each do |folder, features|
92
+ content << "- **[[#{folder.gsub('.md', '')}|#{folder}]]**\n"
93
+
94
+ features.each do |f|
95
+ content << " - #{f.relative_link}\n"
96
+ end
97
+ end
98
+
99
+ @wiki.add_page(filename, content)
100
+ end
101
+ end
@@ -0,0 +1,85 @@
1
+ Gitnesse::Cli.task :run do
2
+ desc "Pulls changes from remote git-based wiki, and runs Cucumber."
3
+
4
+ help do
5
+ <<-EOS
6
+ USAGE: gitnesse run
7
+
8
+ #{desc}
9
+
10
+ Pulls changed features from remote git-based wiki, runs Cucumber, and pushes
11
+ annotated results to the remote git-based wiki if the "annotate_results" setting
12
+ is enabled.
13
+
14
+ Examples:
15
+ gitnesse run # will pull changes, run cucumber, and annotate results
16
+ EOS
17
+ end
18
+
19
+ def perform
20
+ load_and_check_config
21
+ clone_wiki
22
+ extract_features_from_wiki
23
+ create_or_update_local_features
24
+
25
+ puts " Local features updated."
26
+
27
+ remove_existing_results_from_wiki
28
+
29
+ create_hooks
30
+ run_features
31
+ remove_hooks
32
+
33
+ push_annotated_results_to_wiki
34
+
35
+ puts " Done."
36
+ end
37
+
38
+ # Public: Removes existing Gitnesse results from all wiki pages
39
+ #
40
+ # Returns nothing
41
+ def remove_existing_results_from_wiki
42
+ @wiki.pages.each(&:remove_results) if @config.annotate_results
43
+ end
44
+
45
+ # Public: Installs Gitnesse hooks for Cucumber
46
+ #
47
+ # Returns nothing
48
+ def create_hooks
49
+ if @config.annotate_results
50
+ puts " Installing Gitnesse Cucumber hooks."
51
+ Gitnesse::Hooks.create!
52
+ end
53
+ end
54
+
55
+ # Public: Removes installed Gitnesse Cucumber hooks
56
+ #
57
+ # Returns nothing
58
+ def remove_hooks
59
+ if @config.annotate_results
60
+ puts " Removing Gitnesse Cucumber hooks."
61
+ Gitnesse::Hooks.destroy!
62
+ end
63
+ end
64
+
65
+ # Public: Runs Cucumber features
66
+ #
67
+ # Returns nothing
68
+ def run_features
69
+ puts " Running cucumber."
70
+ puts ' -------------------', ''
71
+ system "cucumber #{@config.features_dir}"
72
+ puts ' -------------------', ''
73
+ end
74
+
75
+ # Public: Pushes features with annotations to remote wiki
76
+ #
77
+ # Returns nothing
78
+ def push_annotated_results_to_wiki
79
+ if @config.annotate_results
80
+ puts " Pushing annotated results to remote wiki."
81
+ @wiki.commit
82
+ @wiki.push
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,67 @@
1
+ Dir["#{File.dirname(__FILE__)}/helpers/*.rb"].each { |f| require f }
2
+
3
+ module Gitnesse
4
+ class Cli
5
+ class Task
6
+ include Gitnesse::Cli::ConfigHelpers
7
+ include Gitnesse::Cli::FeatureHelpers
8
+ include Gitnesse::Cli::WikiHelpers
9
+
10
+ attr_accessor :out
11
+
12
+ class << self
13
+ attr_accessor :name
14
+
15
+ def desc(string = nil)
16
+ string ? @desc = string : @desc
17
+ end
18
+
19
+ def help
20
+ block_given? ? @help = yield : @help
21
+ end
22
+ end
23
+
24
+ def initialize(out)
25
+ @out = out
26
+ @config = Gitnesse::Config.instance
27
+ end
28
+
29
+ def perform(*); end
30
+ def description; end
31
+ def help; end
32
+
33
+ private
34
+ def puts(*args)
35
+ out.puts *args
36
+ end
37
+
38
+ def print(*args)
39
+ out.print *args
40
+ end
41
+
42
+ def abort(*args)
43
+ out.puts *args
44
+ exit 1
45
+ end
46
+ end
47
+
48
+ def tasks
49
+ @tasks ||= Hash[self.class.tasks.map { |name, t| [name, t.new(out)] }]
50
+ end
51
+
52
+ class << self
53
+ def task(*names, &block)
54
+ task = Class.new(Task, &block)
55
+ names.map!(&:to_s)
56
+ task.name = names.first
57
+ names.each { |name| tasks[name] = task }
58
+ end
59
+
60
+ def tasks
61
+ @tasks ||= {}
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ Dir[File.dirname(__FILE__) + "/task/*.rb"].each { |f| require(f) }
@@ -0,0 +1,55 @@
1
+ require 'gitnesse'
2
+
3
+ require 'optparse'
4
+ require 'optparse/version'
5
+
6
+ require 'gitnesse/cli/task'
7
+
8
+ module Gitnesse
9
+ class Cli
10
+ attr_accessor :out, :parser
11
+
12
+ def initialize(out = STDOUT)
13
+ @out = out
14
+ setup_parser
15
+ end
16
+
17
+ def parse(args = ARGV)
18
+ parser.parse! args
19
+
20
+ arg = args.shift.to_s
21
+
22
+ if task = tasks[arg]
23
+ task.perform(*args)
24
+ else
25
+ abort "No such task."
26
+ end
27
+ end
28
+
29
+ private
30
+ def setup_parser
31
+ @parser = OptionParser.new do |o|
32
+ o.on_tail '-v', '--version' do
33
+ puts parser.ver
34
+ exit
35
+ end
36
+ end
37
+
38
+ parser.program_name = 'gitnesse'
39
+ parser.version = Gitnesse::VERSION
40
+ end
41
+
42
+ def print(*args)
43
+ out.print *args
44
+ end
45
+
46
+ def puts(*args)
47
+ out.puts *args
48
+ end
49
+
50
+ def abort(*args)
51
+ puts *args
52
+ exit 1
53
+ end
54
+ end
55
+ end