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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e29580781a8605e4065b33ebe1635449dbd6aa3
4
- data.tar.gz: 35f89aa36570bf3b131160a6a8ccfb6ee82e3248
3
+ metadata.gz: 44ef3b279562acfd0f5516c02382a38a70778f0b
4
+ data.tar.gz: fa24abb31a74a7baabcb08921377a3a1a77d3e6b
5
5
  SHA512:
6
- metadata.gz: 51bbffb12a1135f370822409dc4cbcd3c827671d0b82a910370a5f68dc2449da97dc4f10ebd1028a29c7fe55ca042c70bf1cb0d8a5286fc2370d96c996dafccd
7
- data.tar.gz: eac70d0bb708678d15d4604e6d37b392d96271029e514c6cc5d8fb39cef761b626783ea15c9021bda8159937c23650f0f270b22a9e10b868de50c6e88725fcd7
6
+ metadata.gz: 07ab67f28397f6bb2457bbb0d2d665d1718800b3a4ad31a0ff302500a4c6c9511ec190d96c4c64cfc2febb557c0be3f7dc41038cc8425d8ed816cbcc40e5d310
7
+ data.tar.gz: 86fe0d1b98c855524b1a962dd54f07607c70412aaf406be9fa0d4fd928ec3ded01690ec99ad21b39ed945be123d2329f0b14f1f15268f17dca2c38c03ed68e26
data/.duty.yml.sample CHANGED
@@ -1 +1,4 @@
1
- tasks: /path/to/my/project/specific/tasks
1
+ tasks:
2
+ git: /path/to/duty-git/lib/duty/git.rb
3
+ projectA: /path/to/projectA/tasks.rb
4
+ projectB: /path/to/projectB/i_dont_care_about_naming.rb
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
- ## Naming conventions
37
+ ## List of official duty plugins
38
38
 
39
- Task names should be a combination of one verb joined with one or more nouns.
39
+ * [duty-git](https://github.com/JanOwiesniak/duty-git)
40
40
 
41
- Examples:
41
+ ## Extend duty with your own plugins
42
42
 
43
- * `start-feature`
44
- * `continue-feature`
43
+ * Create a new file that implements the plugin behaviour
44
+ * Create a .duty file e.g. in your project dir
45
45
 
46
- ## List of official duty plugins
46
+ ### How does a duty plugin looks like?
47
47
 
48
- * [duty-git](https://github.com/JanOwiesniak/duty-git)
48
+ Example: `/path/to/your/duty-plugins/my_duty_plugin.rb`
49
49
 
50
- ## Extend duty with your own tasks
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
- * Create a new `tasks` dir
53
- * Create one or more duty task files in there
54
- * Create a .duty file e.g. in your home dir
62
+ module MyDutyTasks
63
+ class MyFirstTask < ::Duty::Tasks::Base
64
+ end
55
65
 
56
- ### How does a basic duty task looks like?
66
+ class ContinueFeature < ::Duty::Tasks::Base
67
+ def self.description
68
+ "Continue on an already existing feature"
69
+ end
57
70
 
58
- path/to/your/new/tasks/my_new_task.rb
71
+ def self.usage
72
+ "duty continue-feature <feature-name>"
73
+ end
59
74
 
60
- ```ruby
61
- require 'duty/tasks/base'
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
- module Duty
64
- module Tasks
65
- class MyNewTask < Duty::Tasks::Base
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
- ### How does a .duty file looks like?
110
+ ## Task naming conventions
72
111
 
73
- .duty
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
- tasks:
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 task?
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 task will be immediately available from the CLI.
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(DUTY_CONFIG_FILENAME))
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
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(filename)
6
+ def self.load(config)
7
7
  Duty::Plugins::List.new.tap do |list|
8
- if File.exists?(filename)
9
- duty_config = YAML.load(File.read(filename))
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
@@ -1,3 +1,3 @@
1
1
  module Duty
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3"
3
3
  end
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.2.1
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-28 00:00:00.000000000 Z
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