dirt 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +22 -0
- data/Gemfile.lock +91 -0
- data/MIT-LICENSE +23 -0
- data/README.md +150 -0
- data/core/contexts/commit_git_repository.rb +56 -0
- data/core/contexts/create_basic_face.rb +60 -0
- data/core/contexts/create_default_structure.rb +57 -0
- data/core/contexts/create_git_repository.rb +45 -0
- data/core/contexts/roles/.gitkeep +0 -0
- data/core/contexts/roles/generating.rb +26 -0
- data/core/dirt.rb +14 -0
- data/core/models/.gitkeep +0 -0
- data/core/tests/behaviours/commit_files.feature +36 -0
- data/core/tests/behaviours/create_basic_face.feature +49 -0
- data/core/tests/behaviours/create_default_structure.feature +55 -0
- data/core/tests/behaviours/create_vcs_repository.feature +26 -0
- data/core/tests/behaviours/step_definitions/given.rb +18 -0
- data/core/tests/behaviours/step_definitions/then.rb +55 -0
- data/core/tests/behaviours/step_definitions/when.rb +21 -0
- data/core/tests/behaviours/support/env.rb +100 -0
- data/core/tests/behaviours/support/helpers.rb +21 -0
- data/core/tests/factories.rb +23 -0
- data/core/version.rb +3 -0
- data/faces/cli/bin/dirt +6 -0
- data/faces/cli/integrations/generate_context.feature +40 -0
- data/faces/cli/integrations/generate_face.feature +53 -0
- data/faces/cli/integrations/generate_model.feature +11 -0
- data/faces/cli/integrations/generate_project.feature +143 -0
- data/faces/cli/integrations/generate_role.feature +12 -0
- data/faces/cli/integrations/step_definitions/given.rb +16 -0
- data/faces/cli/integrations/step_definitions/then.rb +48 -0
- data/faces/cli/integrations/step_definitions/when.rb +28 -0
- data/faces/cli/integrations/support/env.rb +21 -0
- data/faces/cli/optparse/main.rb +143 -0
- data/faces/cli/thor/.gitkeep +0 -0
- data/templates/faces/web/template.helpers.rb +4 -0
- data/templates/template.Gemfile +18 -0
- data/templates/template.env.rb +13 -0
- data/templates/template.gitignore +21 -0
- data/templates/template.project_name.rb +14 -0
- metadata +104 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rspec/matchers'
|
2
|
+
|
3
|
+
RSpec::Matchers.define :exist do
|
4
|
+
match do |actual_path|
|
5
|
+
File.exist?(actual_path) == true
|
6
|
+
end
|
7
|
+
|
8
|
+
failure_message_for_should do |actual|
|
9
|
+
"expected '#{actual.to_s}' to exist"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def recent_history(n=1)
|
14
|
+
unless @commands
|
15
|
+
FakeFS.deactivate!
|
16
|
+
@commands = history.to_a
|
17
|
+
FakeFS.activate!
|
18
|
+
end
|
19
|
+
|
20
|
+
@commands.shift(n)
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2014 Tenjin Inc.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
data/core/version.rb
ADDED
data/faces/cli/bin/dirt
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
Feature: it should create new Dirt context in the context directory
|
2
|
+
|
3
|
+
Scenario:
|
4
|
+
Given this feature is unimplemented
|
5
|
+
|
6
|
+
# Happy cases:
|
7
|
+
# dirt generate context CLASSNAME
|
8
|
+
|
9
|
+
# Unhappy cases:
|
10
|
+
# dirt generate context
|
11
|
+
|
12
|
+
|
13
|
+
# Scenario Outline: Running with just project flag
|
14
|
+
# Given I am in "<parent_path>"
|
15
|
+
# When I run dirt generate with:
|
16
|
+
# | flag | value |
|
17
|
+
# | project | <project_name> |
|
18
|
+
# Then it should say "Time to grow, little <project_name>..."
|
19
|
+
# And it should say "Created project structure in <parent_path>/<project_directory>."
|
20
|
+
# And ls should show the following files in "<parent_path>/<project_directory>":
|
21
|
+
# | path |
|
22
|
+
# | config |
|
23
|
+
# | dirt/contexts |
|
24
|
+
# | dirt/contexts/roles |
|
25
|
+
# | dirt/models |
|
26
|
+
# | dirt/tests/behaviours |
|
27
|
+
# | dirt/tests/behaviours/support |
|
28
|
+
# | dirt/tests/behaviours/step_definitions |
|
29
|
+
# | dirt/tests/isolations |
|
30
|
+
# | faces |
|
31
|
+
# Examples:
|
32
|
+
# | parent_path | project_directory | project_name |
|
33
|
+
# | | my_project | My Project |
|
34
|
+
# | a_path/to/the project | my_project | My Project |
|
35
|
+
# | | my_other_project | My Other Project |
|
36
|
+
# | some/other/path | my_other_project | My Other Project |
|
37
|
+
#
|
38
|
+
# Scenario: it should require a project name
|
39
|
+
# When I run dirt generate with no args
|
40
|
+
# Then it should say "Usage: samling [options] arguments"
|
@@ -0,0 +1,53 @@
|
|
1
|
+
Feature: it should create new face with its default contents
|
2
|
+
# === Happy cases ====
|
3
|
+
Scenario Outline: dirt generate face PLATFORM
|
4
|
+
Given this feature is unimplemented
|
5
|
+
Examples:
|
6
|
+
| nope |
|
7
|
+
|
8
|
+
Scenario Outline: dirt generate face PLATFORM/ENGINE
|
9
|
+
Given this feature is unimplemented
|
10
|
+
Examples:
|
11
|
+
| nope |
|
12
|
+
|
13
|
+
# === Unhappy cases ====
|
14
|
+
# dirt generate project --name test --face
|
15
|
+
Scenario: Generate project with name and face but no face arg
|
16
|
+
Given this feature is unimplemented
|
17
|
+
|
18
|
+
# dirt generate face no_platform
|
19
|
+
Scenario: Generate face but platform does not exist
|
20
|
+
Given this feature is unimplemented
|
21
|
+
|
22
|
+
# dirt generate face platform/no_engine
|
23
|
+
Scenario: Generate face but engine does not exist
|
24
|
+
Given this feature is unimplemented
|
25
|
+
|
26
|
+
# Scenario Outline: Running with just project flag
|
27
|
+
# Given I am in "<parent_path>"
|
28
|
+
# When I run dirt generate with:
|
29
|
+
# | flag | value |
|
30
|
+
# | project | <project_name> |
|
31
|
+
# Then it should say "Time to grow, little <project_name>..."
|
32
|
+
# And it should say "Created project structure in <parent_path>/<project_directory>."
|
33
|
+
# And ls should show the following files in "<parent_path>/<project_directory>":
|
34
|
+
# | path |
|
35
|
+
# | config |
|
36
|
+
# | dirt/contexts |
|
37
|
+
# | dirt/contexts/roles |
|
38
|
+
# | dirt/models |
|
39
|
+
# | dirt/tests/behaviours |
|
40
|
+
# | dirt/tests/behaviours/support |
|
41
|
+
# | dirt/tests/behaviours/step_definitions |
|
42
|
+
# | dirt/tests/isolations |
|
43
|
+
# | faces |
|
44
|
+
# Examples:
|
45
|
+
# | parent_path | project_directory | project_name |
|
46
|
+
# | | my_project | My Project |
|
47
|
+
# | a_path/to/the project | my_project | My Project |
|
48
|
+
# | | my_other_project | My Other Project |
|
49
|
+
# | some/other/path | my_other_project | My Other Project |
|
50
|
+
#
|
51
|
+
# Scenario: it should require a project name
|
52
|
+
# When I run dirt generate with no args
|
53
|
+
# Then it should say "Usage: samling [options] arguments"
|
@@ -0,0 +1,143 @@
|
|
1
|
+
Feature: it should create new project with its default contents and an accompanying git repo
|
2
|
+
|
3
|
+
# === Happy cases ====
|
4
|
+
# dirt generate project --name NAME --bare-path PATH
|
5
|
+
Scenario Outline: generate project with just name, assume location is CWD
|
6
|
+
Given I am in "<parent path>"
|
7
|
+
When I generate a project with:
|
8
|
+
| flag | value |
|
9
|
+
| name | <given name> |
|
10
|
+
| bare-path | <bare path> |
|
11
|
+
Then it should say "Time to grow, little <displayed name>..."
|
12
|
+
And it should have called "git init --bare <bare path>/<project directory>.git"
|
13
|
+
And ls should show the following files in "<parent path>/<project directory>":
|
14
|
+
| path |
|
15
|
+
| core/contexts |
|
16
|
+
| core/contexts/roles |
|
17
|
+
| core/models |
|
18
|
+
| core/tests/behaviours |
|
19
|
+
| core/tests/behaviours/support |
|
20
|
+
| core/tests/behaviours/step_definitions |
|
21
|
+
| core/tests/isolations |
|
22
|
+
| faces |
|
23
|
+
| persist |
|
24
|
+
And it should say "Created project structure in <parent path>/<project directory>."
|
25
|
+
And it should say "Comitting and pushing..."
|
26
|
+
And it should have called "git --git-dir "<parent path>/<project directory>/.git" --work-tree "<parent path>/<project directory>" push origin master"
|
27
|
+
Examples:
|
28
|
+
| given name | displayed name | parent path | project directory | bare path |
|
29
|
+
| my project | My Project | /a_path/to/the project | my_project | some/git |
|
30
|
+
| my other project | My Other Project | /some/other/path | my_other_project | different/bares |
|
31
|
+
|
32
|
+
# dirt generate project --name NAME --location PATH --bare-path PATH
|
33
|
+
Scenario Outline: generate project with location
|
34
|
+
Given I am in "/"
|
35
|
+
When I generate a project with:
|
36
|
+
| flag | value |
|
37
|
+
| name | my project |
|
38
|
+
| bare-path | some/git |
|
39
|
+
| location | <parent path> |
|
40
|
+
And it should have called "git init --bare some/git/my_project.git"
|
41
|
+
And it should say "Created project structure in <parent path>/my_project." somewhere
|
42
|
+
And it should have called "git --git-dir "<parent path>/my_project/.git" --work-tree "<parent path>/my_project" push origin master"
|
43
|
+
Examples:
|
44
|
+
| parent path |
|
45
|
+
| /a_path/to/the project |
|
46
|
+
| /some/other/path |
|
47
|
+
|
48
|
+
# dirt generate project --name NAME --bare-path PATH --host HOSTNAME
|
49
|
+
Scenario Outline: generate project with host name, assume user
|
50
|
+
Given I am in "<project path>"
|
51
|
+
And that I am logged in as "<user>" on <platform>
|
52
|
+
When I generate a project with:
|
53
|
+
| flag | value |
|
54
|
+
| name | my project |
|
55
|
+
| bare-path | <bare path> |
|
56
|
+
| host | <host> |
|
57
|
+
And it should have called "ssh <user>\@<host> "git init --bare <bare path>/my_project.git""
|
58
|
+
And it should say "Created project structure in <project path>/my_project." somewhere
|
59
|
+
And it should have called "git --git-dir "<project path>/my_project/.git" --work-tree "<project path>/my_project" push origin master"
|
60
|
+
Examples:
|
61
|
+
| platform | host | user | bare path | project path |
|
62
|
+
| linux | machine1 | userA | some/git | /a_path/to/the project |
|
63
|
+
| windows | machine1 | userA | some/git | /a_path/to/the project |
|
64
|
+
| linux | machine2 | userB | different/bares | /some/other/path |
|
65
|
+
| windows | machine2 | userB | different/bares | /some/other/path |
|
66
|
+
|
67
|
+
# dirt generate project --name NAME --bare-path PATH --host HOSTNAME --user USER
|
68
|
+
Scenario Outline: generate project with host name and user
|
69
|
+
Given I am in "<project path>"
|
70
|
+
When I generate a project with:
|
71
|
+
| flag | value |
|
72
|
+
| name | my project |
|
73
|
+
| bare-path | <bare path> |
|
74
|
+
| host | <host> |
|
75
|
+
| user | <user> |
|
76
|
+
And it should have called "ssh <user>\@<host> "git init --bare <bare path>/my_project.git""
|
77
|
+
And it should say "Created project structure in <project path>/my_project." somewhere
|
78
|
+
And it should have called "git --git-dir "<project path>/my_project/.git" --work-tree "<project path>/my_project" push origin master"
|
79
|
+
Examples:
|
80
|
+
| host | user | bare path | project path |
|
81
|
+
| machine1 | userA | some/git | /a_path/to/the project |
|
82
|
+
| machine2 | userB | different/bares | /some/other/path |
|
83
|
+
|
84
|
+
# dirt generate project --name NAME --face PLATFORM/ENGINE
|
85
|
+
Scenario Outline: Generate project with face
|
86
|
+
Given this feature is unimplemented
|
87
|
+
Examples:
|
88
|
+
| nope |
|
89
|
+
| |
|
90
|
+
|
91
|
+
# dirt generate project --name NAME --location PATH --face PLATFORM/ENGINE
|
92
|
+
Scenario Outline: Generate project with location and face
|
93
|
+
Given this feature is unimplemented
|
94
|
+
Examples:
|
95
|
+
| nope |
|
96
|
+
| |
|
97
|
+
|
98
|
+
# === Unhappy cases ====
|
99
|
+
# dirt generate project
|
100
|
+
Scenario: Generate project without name
|
101
|
+
When I generate a project with:
|
102
|
+
| flag | value |
|
103
|
+
| bare-path | anything |
|
104
|
+
Then it should say the usage
|
105
|
+
And it should exit with an error
|
106
|
+
|
107
|
+
# dirt generate project
|
108
|
+
Scenario: Generate project without bare path
|
109
|
+
When I generate a project with:
|
110
|
+
| flag | value |
|
111
|
+
| name | anything |
|
112
|
+
Then it should say the usage
|
113
|
+
And it should exit with an error
|
114
|
+
|
115
|
+
|
116
|
+
# Scenario Outline: Running with just project flag
|
117
|
+
# Given I am in "<parent_path>"
|
118
|
+
# When I run dirt generate with:
|
119
|
+
# | flag | value |
|
120
|
+
# | project | <project_name> |
|
121
|
+
# Then it should say "Time to grow, little <project_name>..."
|
122
|
+
# And it should say "Created project structure in <parent_path>/<project_directory>."
|
123
|
+
# And ls should show the following files in "<parent_path>/<project_directory>":
|
124
|
+
# | path |
|
125
|
+
# | config |
|
126
|
+
# | core/contexts |
|
127
|
+
# | core/contexts/roles |
|
128
|
+
# | core/models |
|
129
|
+
# | core/tests/behaviours |
|
130
|
+
# | core/tests/behaviours/support |
|
131
|
+
# | core/tests/behaviours/step_definitions |
|
132
|
+
# | core/tests/isolations |
|
133
|
+
# | faces |
|
134
|
+
# Examples:
|
135
|
+
# | parent_path | project_directory | project_name |
|
136
|
+
# | | my_project | My Project |
|
137
|
+
# | a_path/to/the project | my_project | My Project |
|
138
|
+
# | | my_other_project | My Other Project |
|
139
|
+
# | some/other/path | my_other_project | My Other Project |
|
140
|
+
#
|
141
|
+
# Scenario: it should require a project name
|
142
|
+
# When I run dirt generate with no args
|
143
|
+
# Then it should say "Usage: samling [options] arguments"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Given(/^this feature is unimplemented$/) do
|
2
|
+
pending 'This feature is yet to be fleshed out.'
|
3
|
+
end
|
4
|
+
|
5
|
+
Given(/^I am in "(.*?)"$/) do |path|
|
6
|
+
FileUtils.mkdir_p(path)
|
7
|
+
@run_dir = path
|
8
|
+
end
|
9
|
+
|
10
|
+
Given(/^that I am logged in as "(.*?)" on (windows|linux)$/) do |username, platform|
|
11
|
+
if platform == 'linux'
|
12
|
+
ENV['USER'] = username
|
13
|
+
else
|
14
|
+
ENV['USERNAME'] = username
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
Then(/^it should say "(.*?)"$/) do |msg|
|
2
|
+
@output.readline.strip.should == msg
|
3
|
+
end
|
4
|
+
|
5
|
+
Then(/^it should say "(.*?)" somewhere$/) do |msg|
|
6
|
+
pos = @output.pos
|
7
|
+
|
8
|
+
@output.rewind
|
9
|
+
@output.read.split("\n").should include(msg)
|
10
|
+
|
11
|
+
@output.seek(pos)
|
12
|
+
end
|
13
|
+
|
14
|
+
Then(/^it should say the usage$/) do
|
15
|
+
pos = @output.pos
|
16
|
+
|
17
|
+
@output.rewind
|
18
|
+
(@output.read || '').should include 'Usage:'
|
19
|
+
|
20
|
+
@output.seek(pos)
|
21
|
+
end
|
22
|
+
|
23
|
+
Then(/^ls should show the following files in "(.*?)":$/) do |location, table|
|
24
|
+
Dir.chdir(location) do
|
25
|
+
|
26
|
+
# ideally use `tree -ifd` instead
|
27
|
+
|
28
|
+
paths = Dir[location + '/**/*']
|
29
|
+
|
30
|
+
table.hashes.collect do |h|
|
31
|
+
paths.should include h[:path]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Then(/^there should( not)? be a( central)? git repository in "(.*?)"$/) do |exists, central, location|
|
37
|
+
pending 'use ls to check if there is a .git repo in that file'
|
38
|
+
end
|
39
|
+
|
40
|
+
Then(/^it should have called "(.*?)"$/) do |command|
|
41
|
+
FakeFS.deactivate!
|
42
|
+
history.should include command.shellsplit
|
43
|
+
FakeFS.activate!
|
44
|
+
end
|
45
|
+
|
46
|
+
Then(/^it should exit with an error$/) do
|
47
|
+
@exited.should be_true
|
48
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
When(/^I generate a project with:$/) do |table|
|
2
|
+
Dir.chdir(@run_dir || Dir.pwd) do
|
3
|
+
options = table.hashes.collect do |h|
|
4
|
+
["--#{h[:flag]}", "#{h[:value]}"]
|
5
|
+
end.flatten
|
6
|
+
|
7
|
+
input = StringIO.new
|
8
|
+
@output = StringIO.new
|
9
|
+
err = StringIO.new
|
10
|
+
kernel = double('kernel')
|
11
|
+
|
12
|
+
kernel.stub(:exit) do
|
13
|
+
raise KernelExited
|
14
|
+
end
|
15
|
+
|
16
|
+
begin
|
17
|
+
Samling::Cli::Main.new(input, @output, err, kernel).execute!(['generate'] + options)
|
18
|
+
|
19
|
+
@output.rewind
|
20
|
+
rescue KernelExited
|
21
|
+
@exited = true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
When(/^I run dirt generate with no args$/) do
|
27
|
+
expect { step('I run dirt generate with:', table([%w{flag value}])) }.to raise_error(SystemExit)
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require './faces/cli/optparse/main.rb'
|
2
|
+
|
3
|
+
require './core/tests/behaviours/support/env'
|
4
|
+
|
5
|
+
require 'cucumber/rspec/doubles'
|
6
|
+
|
7
|
+
Before do
|
8
|
+
@env_user = ENV['USER']
|
9
|
+
@env_username = ENV['USERNAME']
|
10
|
+
|
11
|
+
@exited = false
|
12
|
+
end
|
13
|
+
|
14
|
+
After do
|
15
|
+
ENV['USER']= @env_user
|
16
|
+
ENV['USERNAME'] = @env_username
|
17
|
+
end
|
18
|
+
|
19
|
+
class KernelExited < Exception
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2014 Tenjin Inc.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
src_dir = File.expand_path('../../../../core', __FILE__)
|
25
|
+
$LOAD_PATH.unshift(src_dir) unless $LOAD_PATH.include?(src_dir)
|
26
|
+
|
27
|
+
require 'dirt'
|
28
|
+
|
29
|
+
require 'optparse'
|
30
|
+
require 'yaml'
|
31
|
+
|
32
|
+
module Samling
|
33
|
+
module Cli
|
34
|
+
# Main command line interface (CLI) controller. Handles standard CLI input.
|
35
|
+
class Main
|
36
|
+
# Defines each of the standard OS interfaces to default values, unless
|
37
|
+
# otherwise specified.
|
38
|
+
def initialize(stdin=STDIN, stdout=STDOUT, stderr=STDERR, kernel=Kernel)
|
39
|
+
$stdin, $stdout, $stderr = stdin, stdout, stderr
|
40
|
+
|
41
|
+
@kernel = kernel
|
42
|
+
end
|
43
|
+
|
44
|
+
# The primary invocation method for the application.
|
45
|
+
# It sets up the components of the application as
|
46
|
+
# required by the input arguments, then runs the Contexts.
|
47
|
+
def execute!(argv)
|
48
|
+
options = parse_args(argv)
|
49
|
+
|
50
|
+
select_and_run_context(options)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Parses the argument array as received from the CLI.
|
54
|
+
def parse_args(args)
|
55
|
+
options = {}
|
56
|
+
args ||= []
|
57
|
+
|
58
|
+
parser = OptionParser.new do |opts|
|
59
|
+
opts.banner = 'Usage: dirt generate [options]'
|
60
|
+
|
61
|
+
opts.separator ''
|
62
|
+
opts.separator 'Specific options:'
|
63
|
+
|
64
|
+
# ===================================
|
65
|
+
# Add option recognisers here
|
66
|
+
# ===================================
|
67
|
+
|
68
|
+
opts.on('-n', '--name NAME',
|
69
|
+
'The human-readable name of the new project. Put it in quotes if you want spaces.') do |name|
|
70
|
+
options[:project_name] = name.titlecase
|
71
|
+
end
|
72
|
+
|
73
|
+
opts.on('-l', '--location PATH',
|
74
|
+
'The parent directory of the new project on the local machine.') do |path|
|
75
|
+
options[:project_parent] = Pathname.new(path)
|
76
|
+
end
|
77
|
+
|
78
|
+
opts.on('-b', '--bare-path PATH',
|
79
|
+
'The parent directory of the new git bare on the host machine. See --host.') do |path|
|
80
|
+
options[:bare_path] = Pathname.new(path)
|
81
|
+
end
|
82
|
+
|
83
|
+
opts.on('-h', '--host ADDRESS',
|
84
|
+
'The IP address or name of the machine where the bare repository will be kept. Defaults to localhost.') do |host|
|
85
|
+
options[:vcs_host] = host
|
86
|
+
end
|
87
|
+
|
88
|
+
opts.on('-u', '--user NAME',
|
89
|
+
'The username to be used to log into the host device. Defaults to the name of the user running this script. See --host.') do |name|
|
90
|
+
options[:vcs_user] = name
|
91
|
+
end
|
92
|
+
|
93
|
+
# opts.on('-n', '--no-git',
|
94
|
+
# 'Skip the git steps.') do |use_git|
|
95
|
+
# options[:use_vcs] = use_git
|
96
|
+
# end
|
97
|
+
|
98
|
+
# opts.on('--version',
|
99
|
+
# 'Print program version and exit.') do |version|
|
100
|
+
# options[:version] = version
|
101
|
+
# end
|
102
|
+
end
|
103
|
+
|
104
|
+
parser.parse!(args)
|
105
|
+
|
106
|
+
# config_options = YAML.load_file(options[:config_path] || './persist/persist.yml')
|
107
|
+
#
|
108
|
+
# options = config_options.merge(options)
|
109
|
+
|
110
|
+
options[:project_parent] ||= Pathname.new(Dir.pwd)
|
111
|
+
options[:vcs_user] ||= ENV['USERNAME'] || ENV['USER']
|
112
|
+
|
113
|
+
# Capture remaining, non-flag normal arguments
|
114
|
+
# options[:arguments] = args
|
115
|
+
|
116
|
+
assert_required!(options, parser)
|
117
|
+
|
118
|
+
return options
|
119
|
+
end
|
120
|
+
|
121
|
+
def assert_required!(options, parser)
|
122
|
+
unless options[:project_name] && options[:bare_path]
|
123
|
+
puts parser
|
124
|
+
@kernel.exit
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def select_and_run_context(options)
|
129
|
+
project_directory = options[:project_name].gsub(' ', '').underscore
|
130
|
+
project_directory = options[:project_parent].expand_path + project_directory
|
131
|
+
|
132
|
+
puts "Time to grow, little #{options[:project_name]}..."
|
133
|
+
|
134
|
+
# puts 'Skipping git steps.'
|
135
|
+
CreateGitRepository.run(project_directory, options[:bare_path], options[:vcs_host], options[:vcs_user])
|
136
|
+
|
137
|
+
puts CreateDefaultStructure.run(project_directory)
|
138
|
+
|
139
|
+
puts CommitGitRepository.run(project_directory)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|