zio 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/zio +34 -28
  3. data/lib/zio/branch.rb +45 -0
  4. data/lib/zio/version.rb +1 -1
  5. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4db5f02cc89e272c47f92ed989bd5022c35d0b0
4
- data.tar.gz: 0ad2c4f329303b13f0fa91ea8f5d94bad7e62fbb
3
+ metadata.gz: a93f4288caee353d34b787a2077bace1b9885dc2
4
+ data.tar.gz: 91b97e0fbe382587ba3e131bfc108f3876b757be
5
5
  SHA512:
6
- metadata.gz: 36d18b74216ee9d0e74084f4017d1b8daf0296b053287fdbd4d8adbabe973674e81b02974fb2dc99319c865c4534c74c1c06aeeeda7d618f4ae07d1a412ba122
7
- data.tar.gz: 7826856fc69910ce3cfea1309396c74eafb63ef5f816a40a24faed9b79751763bce53daf519a84d2969eaaf705e4ed3f024b52eb519be864e63bf73d1e821cb4
6
+ metadata.gz: 9cf83ec05062adc6d080d8f7bf8bc17f1956c4b638b6a66e6352ee474e5c1cfbd6d9990c86acd1d003dcf35a6f9bb982e63411e26b809cb1f4bccb22baefcd11
7
+ data.tar.gz: 645fe7cc8606e9acbda08f5efdca9773b630e3ff46cead41e751bb509e6cebb9b363263db49170c5e5e87d01ca246c5d47b5da5f5679e6752426bb5bcbfbe457
data/bin/zio CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'gli'
3
3
  require 'zio/up'
4
+ require 'zio/branch'
4
5
 
5
6
  begin # XXX: Remove this begin/rescue before distributing your app
6
7
  require 'zio'
@@ -13,47 +14,51 @@ end
13
14
 
14
15
  include GLI::App
15
16
 
16
- program_desc 'Describe your application here'
17
+ program_desc 'Bella zio! Productivity tools'
17
18
 
18
19
  version Zio::VERSION
19
20
 
20
21
  subcommand_option_handling :normal
21
22
  arguments :strict
22
23
 
23
- # desc 'Describe some switch here'
24
- # switch [:s,:switch]
25
- #
26
- # desc 'Describe some flag here'
27
- # default_value 'the default'
28
- # arg_name 'The name of the argument'
29
- # flag [:f,:flagname]
30
-
31
- desc 'Run stash and git pull --rebase on git repos'
24
+ desc 'Stash and pull --rebase on master'
32
25
  command :up do |c|
33
- c.desc 'Dir path'
34
- c.default_value File.expand_path('~/')
35
- c.flag :d
36
-
37
- c.desc 'Dirs set'
38
- c.flag :s
26
+ c.desc 'Parent directory to scan. Apply to any contained git repo'
27
+ c.flag [:d, :directory]
39
28
 
40
- dirsets = YAML.load_file(File.join(ENV['HOME'],'.zio.rc.yml'))[:dirsets]
29
+ c.desc 'Git repos set'
30
+ c.flag [:s, :repos_set]
41
31
 
42
32
  c.action do |_global_options, options, _args|
43
- logger = Zio::UpLogger.new
44
- opts = { dir: options[:d] }
45
- opts[:set] = dirsets[options[:s]] if options[:s]
46
- Zio::Up.new(opts).up
47
- logger.print
33
+ logger = Zio::UpLogger.new
34
+ opts = { dir: options[:d] }
35
+ opts[:set] = $dirsets[options[:s]] if options[:s]
36
+ Zio::Up.new(opts).up
37
+ logger.print
48
38
  end
49
-
50
39
  end
51
40
 
52
- desc 'Describe checkout here'
53
- arg_name 'Describe arguments to checkout here'
54
- command :checkout do |c|
55
- c.action do |_global_options, _options, _args|
56
- puts 'checkout command ran'
41
+ desc 'Branch checkout'
42
+ arg_name 'branch_name'
43
+ command :branch do |c|
44
+ c.desc 'Parent directory to scan. Apply to any contained git repo'
45
+ c.flag [:d, :directory]
46
+
47
+ c.desc 'Git repos set'
48
+ c.flag [:s, :repos_set]
49
+
50
+ c.desc 'Create the branch if does not exists'
51
+ c.switch [:f, :force]
52
+
53
+ c.desc 'If -f the base branch to checkout from'
54
+ c.default_value 'master'
55
+ c.flag [:b, :base_branch]
56
+
57
+ c.action do |_global_options, options, args|
58
+ branch = args[0] || 'master'
59
+ opts = { dir: options[:d], branch: branch, force: options[:f], base_branch: options[:b] }
60
+ opts[:set] = $dirsets[options[:s]] if options[:s]
61
+ Zio::Branch.new(opts).checkout
57
62
  end
58
63
  end
59
64
 
@@ -63,6 +68,7 @@ pre do |_global, _command, _options, _args|
63
68
  # chosen command
64
69
  # Use skips_pre before a command to skip this block
65
70
  # on that command only
71
+ $dirsets = YAML.load_file(File.join(ENV['HOME'], '.zio.rc.yml'))[:dirsets]
66
72
  true
67
73
  end
68
74
 
@@ -0,0 +1,45 @@
1
+ require 'open3'
2
+
3
+ module Zio
4
+ class Branch
5
+ attr_accessor :options
6
+ def initialize(options={})
7
+ @options = options
8
+ raise MISSING_ARGUMENTS unless options[:dir] || options[:set]
9
+ end
10
+
11
+ def checkout
12
+ _paths.each do |path|
13
+ #self.class.new(options).async.pull(path)
14
+ puts path
15
+ stdout, stderr, status = Open3.capture3("cd #{path} && git stash && git rev-parse --verify #{options[:branch]}")
16
+
17
+ # Branch does not exists
18
+ if status.exitstatus != 0 && options[:force]
19
+ stdout, stderr, status = Open3.capture3(
20
+ "cd #{path} && git checkout #{options[:base_branch]} && git checkout -b #{options[:branch]}"
21
+ )
22
+ else
23
+ stdout, stderr, status = Open3.capture3("cd #{path} && git checkout #{options[:branch]}")
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ def pull(path)
30
+ stdout, stderr, status = Open3.capture3("cd #{path} && git stash && git checkout master && git pull --rebase")
31
+ publish 'up_capture_complete', [path, stdout, stderr, status]
32
+ end
33
+
34
+ def _paths
35
+ return options[:set] unless options[:set].nil?
36
+ @_paths ||= begin
37
+ Dir.foreach(options[:dir]).map do |path|
38
+ next if path == '.' || path == '..' || !File.exists?(File.expand_path(path, options[:dir]) + '/.git')
39
+ ab_path = File.expand_path(path, options[:dir])
40
+ File.directory?(ab_path) ? ab_path : nil
41
+ end.compact
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module Zio
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Your Name Here
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-31 00:00:00.000000000 Z
11
+ date: 2015-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -114,6 +114,7 @@ files:
114
114
  - features/support/env.rb
115
115
  - features/zio.feature
116
116
  - lib/zio.rb
117
+ - lib/zio/branch.rb
117
118
  - lib/zio/exceptions.rb
118
119
  - lib/zio/up.rb
119
120
  - lib/zio/version.rb