duty 0.2.1 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.duty.yml.sample +4 -1
- data/README.md +75 -29
- data/lib/duty/cli.rb +6 -2
- data/lib/duty/config.rb +0 -0
- data/lib/duty/config_loader.rb +46 -0
- data/lib/duty/plugins.rb +3 -7
- data/lib/duty/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44ef3b279562acfd0f5516c02382a38a70778f0b
|
4
|
+
data.tar.gz: fa24abb31a74a7baabcb08921377a3a1a77d3e6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07ab67f28397f6bb2457bbb0d2d665d1718800b3a4ad31a0ff302500a4c6c9511ec190d96c4c64cfc2febb557c0be3f7dc41038cc8425d8ed816cbcc40e5d310
|
7
|
+
data.tar.gz: 86fe0d1b98c855524b1a962dd54f07607c70412aaf406be9fa0d4fd928ec3ded01690ec99ad21b39ed945be123d2329f0b14f1f15268f17dca2c38c03ed68e26
|
data/.duty.yml.sample
CHANGED
data/README.md
CHANGED
@@ -25,7 +25,7 @@ This gem supports a simple shell completion for
|
|
25
25
|
To enable this feature load the completion functions:
|
26
26
|
|
27
27
|
```
|
28
|
-
source duty.completion
|
28
|
+
$ source duty.completion
|
29
29
|
```
|
30
30
|
|
31
31
|
## Usage
|
@@ -34,64 +34,110 @@ source duty.completion
|
|
34
34
|
$ duty <task> [<args>]
|
35
35
|
```
|
36
36
|
|
37
|
-
##
|
37
|
+
## List of official duty plugins
|
38
38
|
|
39
|
-
|
39
|
+
* [duty-git](https://github.com/JanOwiesniak/duty-git)
|
40
40
|
|
41
|
-
|
41
|
+
## Extend duty with your own plugins
|
42
42
|
|
43
|
-
*
|
44
|
-
*
|
43
|
+
* Create a new file that implements the plugin behaviour
|
44
|
+
* Create a .duty file e.g. in your project dir
|
45
45
|
|
46
|
-
|
46
|
+
### How does a duty plugin looks like?
|
47
47
|
|
48
|
-
|
48
|
+
Example: `/path/to/your/duty-plugins/my_duty_plugin.rb`
|
49
49
|
|
50
|
-
|
50
|
+
```ruby
|
51
|
+
require 'duty'
|
52
|
+
|
53
|
+
module MyDutyPlugin
|
54
|
+
def self.tasks
|
55
|
+
[
|
56
|
+
MyDutyTasks::MyFirstTask,
|
57
|
+
MyDutyTasks::ContinueFeature
|
58
|
+
]
|
59
|
+
end
|
60
|
+
end
|
51
61
|
|
52
|
-
|
53
|
-
|
54
|
-
|
62
|
+
module MyDutyTasks
|
63
|
+
class MyFirstTask < ::Duty::Tasks::Base
|
64
|
+
end
|
55
65
|
|
56
|
-
|
66
|
+
class ContinueFeature < ::Duty::Tasks::Base
|
67
|
+
def self.description
|
68
|
+
"Continue on an already existing feature"
|
69
|
+
end
|
57
70
|
|
58
|
-
|
71
|
+
def self.usage
|
72
|
+
"duty continue-feature <feature-name>"
|
73
|
+
end
|
59
74
|
|
60
|
-
|
61
|
-
|
75
|
+
def valid?
|
76
|
+
!!feature_name
|
77
|
+
end
|
78
|
+
|
79
|
+
# Everthing in here will be executed sequential
|
80
|
+
def execute
|
81
|
+
|
82
|
+
# Execute ruby code
|
83
|
+
ruby("Do something useful in ruby") { Object.new }
|
62
84
|
|
63
|
-
|
64
|
-
|
65
|
-
|
85
|
+
# Execute something on the shell
|
86
|
+
sh("Checkout `feature/#{feature_name}` branch") { "git checkout feature/#{feature_name}" }
|
87
|
+
|
88
|
+
# Wrap things up in a parallel block if you want to run commands in isolation
|
89
|
+
# A failing command inside a parallel does not stop the sequential execution of outer commands
|
90
|
+
parallel { ruby("Run ruby in isolation") { raise RuntimeError.new } }
|
91
|
+
|
92
|
+
# This will be executed even if the ruby above raises an RuntimeError
|
93
|
+
parallel { sh("Run shell in isolation") { 'pwd' } }
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def feature_name
|
100
|
+
@feature_name =|| @arguments.first
|
66
101
|
end
|
67
102
|
end
|
68
103
|
end
|
104
|
+
|
105
|
+
# Return your duty module
|
106
|
+
|
107
|
+
MyDutyPlugin
|
69
108
|
```
|
70
109
|
|
71
|
-
|
110
|
+
## Task naming conventions
|
72
111
|
|
73
|
-
.
|
112
|
+
A task class named `StartFeature` would be accessible through the CLI via.
|
113
|
+
Task names should be a combination of one verb joined with one or more nouns.
|
74
114
|
|
75
115
|
```
|
76
|
-
|
77
|
-
git: /path/to/my/git/specific/tasks
|
78
|
-
projectA: /path/to/my/projectA/specific/tasks
|
79
|
-
projectB: /path/to/my/projectB/specific/tasks
|
116
|
+
$ duty start-feature
|
80
117
|
```
|
81
118
|
|
82
|
-
### How to use my own
|
119
|
+
### How to use my own tasks?
|
120
|
+
|
121
|
+
Create a duty plugin and add it to your `.duty` file.
|
122
|
+
|
123
|
+
```
|
124
|
+
tasks:
|
125
|
+
git: /path/to/duty-git/lib/duty/git.rb
|
126
|
+
projectA: /path/to/projectA/my_duty_plugin.rb
|
127
|
+
projectB: /path/to/projectB/i_dont_care_about_naming.rb
|
128
|
+
```
|
83
129
|
|
84
|
-
Your new
|
130
|
+
Your new tasks will be immediately available from the CLI.
|
85
131
|
|
86
132
|
```
|
87
|
-
duty
|
133
|
+
$ duty
|
88
134
|
```
|
89
135
|
|
90
136
|
Fire up the CLI and execute your new task.
|
91
137
|
Duty will tell you what you have to do next.
|
92
138
|
|
93
139
|
```
|
94
|
-
duty <your-task>
|
140
|
+
$ duty <your-task>
|
95
141
|
```
|
96
142
|
|
97
143
|
## Contributing
|
data/lib/duty/cli.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'duty/config_loader'
|
1
2
|
require 'duty/io'
|
2
3
|
require 'duty/registry'
|
3
4
|
require 'duty/plugins'
|
@@ -6,13 +7,12 @@ require 'duty/views'
|
|
6
7
|
|
7
8
|
module Duty
|
8
9
|
class CLI
|
9
|
-
DUTY_CONFIG_FILENAME = '.duty.yml'
|
10
10
|
attr_reader :registry
|
11
11
|
|
12
12
|
def initialize(args)
|
13
13
|
@input = Duty::IO::CLI::Input.new(args)
|
14
14
|
@output = Duty::IO::CLI::Output.new($stdout, $stderr)
|
15
|
-
@registry = Duty::Registry.register(Duty::Plugins.load(
|
15
|
+
@registry = Duty::Registry.register(Duty::Plugins.load(load_config))
|
16
16
|
end
|
17
17
|
|
18
18
|
def exec
|
@@ -66,5 +66,9 @@ module Duty
|
|
66
66
|
def verbose?
|
67
67
|
input.verbose?
|
68
68
|
end
|
69
|
+
|
70
|
+
def load_config
|
71
|
+
Duty::ConfigLoader.new.load(Dir.pwd)
|
72
|
+
end
|
69
73
|
end
|
70
74
|
end
|
data/lib/duty/config.rb
ADDED
File without changes
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module Duty
|
5
|
+
class ConfigLoader
|
6
|
+
DUTY_CONFIG_FILENAME = '.duty.yml'
|
7
|
+
|
8
|
+
def initialize(root_directory = nil)
|
9
|
+
@root_directory = root_directory
|
10
|
+
end
|
11
|
+
|
12
|
+
def load(base_dir)
|
13
|
+
return default_config unless path = find_closest_config_file(base_dir)
|
14
|
+
load_config_file(path)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def default_config
|
20
|
+
{ "tasks" => [] }
|
21
|
+
end
|
22
|
+
|
23
|
+
def find_closest_config_file(base_dir)
|
24
|
+
candidates = dirs_to_search(base_dir).map do |dir|
|
25
|
+
File.join(dir, DUTY_CONFIG_FILENAME)
|
26
|
+
end
|
27
|
+
candidates.find do |path|
|
28
|
+
File.exists?(path)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def dirs_to_search(base_dir)
|
33
|
+
starting_dir = File.expand_path(base_dir)
|
34
|
+
dirs_to_search = []
|
35
|
+
Pathname.new(starting_dir).ascend do |path|
|
36
|
+
break if path.to_s == @root_directory
|
37
|
+
dirs_to_search << path.to_s
|
38
|
+
end
|
39
|
+
dirs_to_search << Dir.home
|
40
|
+
end
|
41
|
+
|
42
|
+
def load_config_file(path)
|
43
|
+
YAML.load(File.read(path))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/duty/plugins.rb
CHANGED
@@ -3,14 +3,10 @@ require 'yaml'
|
|
3
3
|
|
4
4
|
module Duty
|
5
5
|
module Plugins
|
6
|
-
def self.load(
|
6
|
+
def self.load(config)
|
7
7
|
Duty::Plugins::List.new.tap do |list|
|
8
|
-
|
9
|
-
|
10
|
-
tasks = duty_config["tasks"]
|
11
|
-
tasks.each do |namespace, plugin_entry_point|
|
12
|
-
list << Plugin.new(namespace, plugin_entry_point)
|
13
|
-
end
|
8
|
+
config["tasks"].each do |namespace, plugin_entry_point|
|
9
|
+
list << Plugin.new(namespace, plugin_entry_point)
|
14
10
|
end
|
15
11
|
end
|
16
12
|
end
|
data/lib/duty/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Owiesniak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -62,6 +62,8 @@ files:
|
|
62
62
|
- duty.gemspec
|
63
63
|
- lib/duty.rb
|
64
64
|
- lib/duty/cli.rb
|
65
|
+
- lib/duty/config.rb
|
66
|
+
- lib/duty/config_loader.rb
|
65
67
|
- lib/duty/io.rb
|
66
68
|
- lib/duty/io/cli.rb
|
67
69
|
- lib/duty/meta.rb
|