ora-cli 0.1.3 → 0.1.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04ffb993c92edbd65650f38d40babfaaf6b4dbb9
4
- data.tar.gz: a52806ca086055d8f89111ecb1eb825467855abc
3
+ metadata.gz: e6baf3c45bb5e052285bc2c476902b4a329f533f
4
+ data.tar.gz: dee459f8cf75961b8a9a4828109a18fe342e1dba
5
5
  SHA512:
6
- metadata.gz: 3e7775607b46f76a481da64b6ba2ad446438655f2f8d705df62c997af9d4268ade3f2d8306447ae8a310eee1e3d1a283bbb5c6a2549d01c94bfe6206042aa9e3
7
- data.tar.gz: 6b6e4ad0073c0df80048f68bef4b599f6a8b61ffdfb51617fa056c861645218d583a213c444a6e7a1a6ae1aed50d9c1079f654645cab4762bd108de62a614bce
6
+ metadata.gz: cf4e37a5f7c2ac3b45a3fc75b390f082abfed1a01c596c9abd37ff57c375eedc8a88816c4a9a95809e106bc249b07c82c865276f9f1540c2d30ed2643df1f5cc
7
+ data.tar.gz: d4c640b7fdc6418310b2e3d9d10e01ef90044596e8b8cc85ae33815c83e58e7b37df505d0c2d20ab57acb1326123e50c2bc9ccb1eae5a325ac84babfd5bfb784
data/README.md CHANGED
@@ -16,15 +16,17 @@ A command line tool to automate development workflow in ORA
16
16
  ## Tasks
17
17
 
18
18
  `new_feature_branch`: Help to create a new branch from up-to-date develop branch
19
-
19
+
20
20
  `push_feature_branch`: Help to push your feature branch to remote ready for pull request
21
-
21
+
22
22
  `push_to_staging`: Help to push your feature branch to staging
23
-
23
+
24
24
  `push_to_uat`: Help to push your feature branch to uat
25
-
25
+
26
26
  `push_to_master`: Help to push your feature branch to develop and master branches with a version tag
27
27
 
28
+ `switch_branch`: Help to switch branch without thinking about dirty files`
29
+
28
30
  ## Contributing
29
31
 
30
32
  Bug reports and pull requests are welcome on GitHub at https://github.com/ducktyper/ora-cli.
data/lib/ora/cli/bash.rb CHANGED
@@ -1,9 +1,12 @@
1
+ require "ora/cli/print.rb"
2
+
1
3
  module Ora::Cli
2
4
  class Bash
3
5
  def initialize(target, from: nil, print: Print.new)
4
- @target = target
5
- @from = from
6
- @print = print
6
+ @target = target
7
+ @from = from
8
+ @print = print
9
+ @success = true
7
10
  end
8
11
 
9
12
  def silent command
@@ -11,10 +14,12 @@ module Ora::Cli
11
14
  end
12
15
 
13
16
  def run commands
17
+ @success = true
14
18
  unprocessed_commands = extract commands
15
19
 
16
20
  outputs = []
17
21
  while (command = complete unprocessed_commands.shift)
22
+ next if command.empty?
18
23
  break unless call command do |output|
19
24
  outputs.push output
20
25
  end
@@ -25,6 +30,14 @@ module Ora::Cli
25
30
  join outputs
26
31
  end
27
32
 
33
+ def select command
34
+ `#{move}#{command} | #{selecta}`
35
+ end
36
+
37
+ def success?
38
+ @success
39
+ end
40
+
28
41
  private
29
42
  def move
30
43
  "cd #{@from} && " if @from
@@ -55,7 +68,7 @@ module Ora::Cli
55
68
  def call command
56
69
  @print.green command
57
70
 
58
- success =
71
+ @success =
59
72
  if method? command
60
73
  call_method command
61
74
  else
@@ -63,8 +76,8 @@ module Ora::Cli
63
76
  $?.success?
64
77
  end
65
78
 
66
- alert command unless success
67
- success
79
+ alert command unless @success
80
+ @success
68
81
  end
69
82
  def method? command
70
83
  command.start_with? ":"
@@ -92,5 +105,9 @@ module Ora::Cli
92
105
  @print.red(complete unprocessed_command)
93
106
  end
94
107
  end
108
+
109
+ def selecta
110
+ @selecta ||= File.expand_path('../../../../bin/ora_selecta', __FILE__)
111
+ end
95
112
  end
96
113
  end
data/lib/ora/cli/stdin.rb CHANGED
@@ -1,8 +1,11 @@
1
+ require "ora/cli/print.rb"
2
+
1
3
  module Ora::Cli
2
4
  class Stdin
3
- def initialize(inputs = [], print: Print.new)
4
- @inputs = inputs
5
+ def initialize(bash:, print: Print.new, inputs: [])
6
+ @bash = bash
5
7
  @print = print
8
+ @inputs = inputs
6
9
  end
7
10
 
8
11
  def gets(pattern = '')
@@ -18,5 +21,9 @@ module Ora::Cli
18
21
 
19
22
  input
20
23
  end
24
+
25
+ def select(command)
26
+ @inputs.shift || @bash.select(command)
27
+ end
21
28
  end
22
29
  end
data/lib/ora/cli/task.rb CHANGED
@@ -1,12 +1,18 @@
1
+ require "ora/cli/bash.rb"
2
+ require "ora/cli/print.rb"
3
+ require "ora/cli/stdin.rb"
4
+
1
5
  module Ora::Cli
2
6
  class Task
3
7
  attr_reader :branch, :stdin, :print
4
8
 
9
+ MAIN_BRANCHES = %w{master develop staging uat}
10
+
5
11
  def initialize(from, inputs: [], print: Print.new)
6
12
  @from = from
7
13
  @bash = Bash.new(self, from: @from, print: print)
8
14
  @branch = current_branch
9
- @stdin = Stdin.new(inputs, print: print)
15
+ @stdin = Stdin.new(bash: @bash, print: print, inputs: inputs)
10
16
  @print = print
11
17
  end
12
18
 
@@ -18,13 +24,21 @@ module Ora::Cli
18
24
  raise "Override this method in subclass"
19
25
  end
20
26
 
27
+ def success?
28
+ @bash.success?
29
+ end
30
+
21
31
  private
22
32
  def current_branch
23
33
  @bash.silent('git branch | grep \\*').sub("*", "").strip
24
34
  end
25
35
 
36
+ def main_branch?
37
+ MAIN_BRANCHES.include? branch
38
+ end
39
+
26
40
  def feature_branch!
27
- if %w{master develop staging uat}.include?(branch)
41
+ if main_branch?
28
42
  @print.red "Please checkout feature branch first!"
29
43
  false
30
44
  end
@@ -1,3 +1,5 @@
1
+ require 'ora/cli/task'
2
+
1
3
  module Ora::Cli
2
4
  class NewFeatureBranch < Task
3
5
  attr_reader :branch_name
@@ -1,3 +1,5 @@
1
+ require 'ora/cli/task'
2
+
1
3
  module Ora::Cli
2
4
  class PushFeatureBranch < Task
3
5
  def commands
@@ -1,3 +1,5 @@
1
+ require 'ora/cli/task'
2
+
1
3
  module Ora::Cli
2
4
  class PushToMaster < Task
3
5
  attr_reader :version
@@ -1,3 +1,5 @@
1
+ require 'ora/cli/task'
2
+
1
3
  module Ora::Cli
2
4
  class PushToStaging < Task
3
5
 
@@ -1,3 +1,5 @@
1
+ require 'ora/cli/task'
2
+
1
3
  module Ora::Cli
2
4
  class PushToUat < Task
3
5
 
@@ -0,0 +1,41 @@
1
+ require 'ora/cli/task'
2
+
3
+ module Ora::Cli
4
+ class SwitchBranch < Task
5
+ attr_reader :target_branch
6
+
7
+ def commands
8
+ '
9
+ :only_feature_branch_can_be_dirty!
10
+ :switch_to
11
+ git stash save -u "OraCli"
12
+ git checkout #{target_branch}
13
+ #{apply_stash}
14
+ '
15
+ end
16
+
17
+ private
18
+ def only_feature_branch_can_be_dirty!
19
+ if main_branch? && dirty?
20
+ print.red "#{branch} branch can't be dirty!"
21
+ return false
22
+ end
23
+ end
24
+
25
+ def switch_to
26
+ @target_branch = stdin.select("git branch | grep '^ ' | sed 's/^ //'")
27
+ end
28
+
29
+ def apply_stash
30
+ return nil if target_stash_revision.empty?
31
+ "git stash pop #{target_stash_revision}"
32
+ end
33
+ def target_stash_revision
34
+ @bash.silent("git stash list | grep '#{target_stash_name}' | sed s/:.*//").strip
35
+ end
36
+ def target_stash_name
37
+ "On #{target_branch}: OraCli"
38
+ end
39
+
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  module Ora
2
2
  module Cli
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
data/lib/ora/cli.rb CHANGED
@@ -1,19 +1,11 @@
1
+ require "ora/cli/version.rb"
2
+
1
3
  module Ora
2
4
  module Cli
3
5
  def self.run task, from
6
+ require "ora/cli/tasks/#{task}"
4
7
  class_name = task.split('_').map(&:capitalize).join
5
8
  Object.const_get("Ora::Cli::#{class_name}").new(from).run
6
9
  end
7
10
  end
8
11
  end
9
-
10
- require "ora/cli/bash.rb"
11
- require "ora/cli/print.rb"
12
- require "ora/cli/stdin.rb"
13
- require "ora/cli/task.rb"
14
- require "ora/cli/version.rb"
15
- require "ora/cli/tasks/new_feature_branch.rb"
16
- require "ora/cli/tasks/push_feature_branch.rb"
17
- require "ora/cli/tasks/push_to_master.rb"
18
- require "ora/cli/tasks/push_to_staging.rb"
19
- require "ora/cli/tasks/push_to_uat.rb"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ora-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ducksan Cho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-30 00:00:00.000000000 Z
11
+ date: 2016-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -79,6 +79,7 @@ files:
79
79
  - lib/ora/cli/tasks/push_to_master.rb
80
80
  - lib/ora/cli/tasks/push_to_staging.rb
81
81
  - lib/ora/cli/tasks/push_to_uat.rb
82
+ - lib/ora/cli/tasks/switch_branch.rb
82
83
  - lib/ora/cli/version.rb
83
84
  - ora-cli.gemspec
84
85
  homepage: https://orahq.com