ferrets_on_fire 0.0.1 → 0.0.2

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: e10279082200ad3c59578490354c5583b2d55053
4
- data.tar.gz: e4270068759afb2b7d642330f99e72dfab844d8d
3
+ metadata.gz: bac851bccbedbc222f6d06b474250296ef76613b
4
+ data.tar.gz: 172a42f14e03ef71e07638b8ffd7c032c927a2d6
5
5
  SHA512:
6
- metadata.gz: af775ab186a031447f7cba5e7ef4c488027c763387f825d0ada33380efbf88487fdcd1303dd4fda9b0a805396a5150cfe582e035d1de40dd6102ce17c8fb1cba
7
- data.tar.gz: f827d326ee118b2743fcb4c185828df2481b7ae13712a9cc2f4e69f542317975069cf658320eb6b6c924a174b1b161ee83931a25b4a1bea31c64112b2551a5de
6
+ metadata.gz: 3a96c36a9e4c69e5a6fabb37d453bc681e6f14e013f5e85168ca64d9d7cc2782492b814cb08932a39ab208a722484c627d3c7a503d395be846614953f1646938
7
+ data.tar.gz: 659c558def859eb29631fd2a8bb314c754c91dd28d65beb7300f859a1b64f4850de06e0f9910eaa30b71aa721f34c39b56b7b13bfa193ba4941a8fdf5af45604
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Ferrets on Fire
2
2
 
3
- Supercharge your CLI tools. This opinionated, burning gem helps you to write powerful CLI tools of all sizes without
4
- caring about the clutter!
3
+ Supercharge your CLI tools. This opinionated, burning ruby gem helps you to write powerful CLI tools of all sizes
4
+ without caring about the clutter!
5
5
 
6
6
  **WARNING: This project is work in progress, use with care.**
7
7
 
@@ -10,10 +10,10 @@ caring about the clutter!
10
10
 
11
11
  - Super simple and lightweight DSL.
12
12
  - Beautiful output (especially on OSX).
13
- - Builtin tasks for git, bundler, ...
14
- - Framework for system calls: Logging, benchmarking, error handling and more.
13
+ - Builtin routines for git, bundler, ...
14
+ - Framework for system calls: Logging, benchmarking, error handling, crash reporting and more.
15
15
  - Support CLI switches, options, arguments and commands.
16
- - Supports Logging, colors, progress bars, questions and much more.
16
+ - Supports Logging, colors, progress bars, questions, yes/no and much more.
17
17
  - Builtin IoC container.
18
18
  - Ferrets.
19
19
 
@@ -21,9 +21,7 @@ caring about the clutter!
21
21
 
22
22
  - Command API
23
23
  - Code formatting, refactoring, documentation
24
- - Project, usage & API documentation
25
24
  - Progress bars
26
- - Highline
27
25
  - DSL for IoC container
28
26
  - RSpecs
29
27
  - CI build
@@ -41,7 +39,7 @@ or via `Gemfile`:
41
39
  gem 'ferrets_on_fire'
42
40
  ```
43
41
 
44
- (Don't forget to run `bundle install`)
42
+ Don't forget to run `bundle install`.
45
43
 
46
44
 
47
45
  ## Usage
@@ -60,13 +58,114 @@ After that you can already you the fancy ferret DSL:
60
58
  require '_'
61
59
 
62
60
  # Some output
63
- info 'Running the test suit!'
61
+ info 'Running the test suite!'
64
62
 
65
63
  # Run `bundle exec rspec spec/`
66
64
  run 'rspec spec/', bundler: true
67
65
  ```
68
66
 
69
67
 
68
+ ## DSL
69
+
70
+ This is a complete documentation of the DSL containing all methods, theirs params etc.
71
+
72
+
73
+ ### General
74
+
75
+ - `root()`: Returns the root path of the project, which uses this gem. Requires that the project uses bundler.
76
+ - `load_lib()`: Adds the `lib` dir of the project, which uses this gem, to the LOAD_PATH.
77
+
78
+
79
+ ### Logging & Interaction
80
+
81
+ - `banner(string, color: :white, background: :black)`: Prints a banner
82
+ - `string`: The banner.
83
+ - `color`: Optional. Text color.
84
+ - `background`: Optional. Background color.
85
+
86
+ - `info(msg)`: Prints an information message. Color is white.
87
+ - `msg`: Message to print.
88
+
89
+ - `action(msg)`: Prints an action message. Color is blue. If a block is given, it turns in a success message after the
90
+ block was yielded. Returns the return value of the block.
91
+ - `msg`: Message to print.
92
+
93
+ - `warn(msg)`: Prints a warning message. Color is yellow.
94
+ - `msg`: Message to print.
95
+
96
+ - `success(msg)`: Prints a success message. Color is green.
97
+ - `msg`: Message to print.
98
+
99
+ - `error(msg)`: Prints an error message. Color is red.
100
+ - `msg`: Message to print.
101
+
102
+ - `choose(msg, options, default: nil)`: Let's the user choose out of options. It returns the chosen option.
103
+ - `msg`: Prompt message.
104
+ - `options`: Array of options.
105
+ - `default`: Optional. Default option value.
106
+
107
+ - `yes_no(msg, default = true)`: Asks the user a simple yes/no question, which can be answered with `y` or `n`. Returns
108
+ true if the user has answered with yes. false for no.
109
+ - `msg`: Prompt message
110
+ - `default`: true = yes is the default, false = no is the default
111
+
112
+ - `linebreak()`: Prints a linebreak
113
+
114
+ - `highlight(str)`: Highlights a string for the use with info like: `info("foo #{highlight(bar)}!")`
115
+
116
+ - `crash(msg, output, command: nil, exit: true)`: Prints a crash report
117
+ - `msg`: Error message.
118
+ - `command`: Optional. Shell command if available.
119
+ - `exit`: Optional. If true the script will exit.
120
+
121
+
122
+
123
+ ### Shell commands
124
+
125
+ - `bundle(dir: nil)`: Runs `bundle install` in the specified dir. Bundler is configured for
126
+ optimal performance.
127
+ - `dir`: Optional. The directory to run in. If empty, the current working dir is used.
128
+
129
+ - `run(cmd, dir: nil, exit_on_failure: true, quiet: false, return_exit_code: false, as: nil, bundler: false, rails_env: nil)`:
130
+ Executes a shell command. The command will be logged as an action (blue), which turns in a success message after the
131
+ command finished successful. A crash report is generated if the command fails. stderr is redirected to stdout. It
132
+ returns stdout. The command is benchmarked and the time is printed automatically.
133
+ - `cmd`: Command to run.
134
+ - `dir`: Optional. Working dir for the command. If empty, the current working dir is used.
135
+ - `exit_on_failure`: Optional. Exit if the command fails?
136
+ - `quiet`: Optional. Don't log anything if true.
137
+ - `return_exit_code`: Optional. If true, the exit code is returned rather than the output.
138
+ - `as`: Optional. Label to use for logging instead of the command.
139
+ - `bundler`: Optional. Run command with `bundle exec`?.
140
+ - `rails_env`: Optional. Set the `RAILS_ENV` variable.
141
+
142
+
143
+ ### git
144
+
145
+ - `update_git_repo(path: nil, desired_branch: nil, skip_update: false)`: Runs a git pull in the specified directory and
146
+ runs the `bin/update` command within that directory, if it exists.
147
+ - `path`: Optional. The directory with the git repo. If not specified, the current working directory is used.
148
+ - `desired_branch`: Optional. Branch that should be checked out - if it's not checked out, a warning is printed.
149
+ - `skip_update`: Optional. Don't run `bin/update` if true.
150
+
151
+ - `clone_git_repo(remote, target: '', checkout: nil, skip_setup: false)`: Clones a git repository to a local directory
152
+ and runs `bin/setup` if that exists
153
+ - `remote`: The git remote URL.
154
+ - `target`: Optional. Local directory to clone into. If empty, the repo name is used.
155
+ - `checkout`: Optional. Checkout a commit, branch, etc.
156
+ - `skip_setup`: Optional. Don't run `bin/setup` if true.
157
+
158
+ - `git_checkout(dir, checkout)`: Checks out a specific commit, tag, branch etc.
159
+ - `dir`: Local dir with the repo
160
+ - `checkout`: Ref to checkout
161
+
162
+ - `find_git_tags(dir)`: Returns all tags in a git repo
163
+ - `dir`: Local dir with the repo
164
+
165
+ - `get_git_master_ref(dir)`: Returns a Rugged Ref object for the `origin/master` ref
166
+ - `dir`: Local dir with the repo
167
+
168
+
70
169
 
71
170
  ## Open Source
72
171
 
@@ -4,8 +4,6 @@ class FerretsOnFire::Command
4
4
  attr_reader :name, :desc, :default, :action_block
5
5
  attr_accessor :global_options, :options, :args
6
6
 
7
- include FerretsOnFire::DSL
8
-
9
7
  public def initialize(name, desc, default, &block)
10
8
  @name = name.to_sym
11
9
  @desc = desc
@@ -18,8 +16,4 @@ class FerretsOnFire::Command
18
16
  public def action(&block)
19
17
  @action_block = block
20
18
  end
21
-
22
- public def run
23
- yield @block
24
- end
25
19
  end
@@ -1,15 +1,4 @@
1
- module FerretsOnFire::DSL::Declaration
2
- public def bundle(dir: nil)
3
- # Set bundler parallel jobs count
4
- if run('sysctl -n hw.ncpu', quiet: true, return_exit_code: true).zero?
5
- number_of_cores = run('sysctl -n hw.ncpu', quiet: true).strip.to_i - 1
6
- run("bundle config --global jobs #{number_of_cores}", quiet: true)
7
- end
8
-
9
- run 'bundle', dir: dir, as: 'bundler'
10
- end
11
-
12
-
1
+ module FerretsOnFire::DSL::DeclarationDSL
13
2
  public def description(desc)
14
3
  @desc = desc
15
4
  end
@@ -0,0 +1,50 @@
1
+ module FerretsOnFire::DSL::GitDSL
2
+ # Updates the git repository in the current directory and runs bin/update
3
+ # @param [String] path The directory to use, default is the current one
4
+ public def update_git_repo(path: nil, desired_branch: nil, skip_update: false)
5
+ run 'git pull -r --autostash', dir: path, as: 'git pull'
6
+
7
+ # get current branch name
8
+ if desired_branch
9
+ current_branch = run('git branch | grep \*', dir: path, quiet: true).sub('*', '').strip
10
+
11
+ unless current_branch == desired_branch
12
+ warn "WARNING: Current branch is not #{desired_branch} (it's #{current_branch})"
13
+ end
14
+ end
15
+
16
+ run('bin/update', dir: path, as: 'bin/update', bundler: true) if !skip_update && File.exists?('bin/update')
17
+ end
18
+
19
+
20
+ public def clone_git_repo(remote, target: '', checkout: nil, skip_setup: false)
21
+ run "git clone #{remote} #{target}", as: 'clone git repo'
22
+ run "git checkout #{checkout}", as: "checkout #{checkout}", dir: target unless checkout.nil?
23
+ run('bin/setup', dir: target, as: 'bin/setup', bundler: true) if !skip_setup && File.exists?('bin/setup')
24
+ end
25
+
26
+ private def _git_setup(dir)
27
+ require 'rugged'
28
+ Rugged::Repository.new(dir)
29
+ end
30
+
31
+
32
+ public def git_checkout(dir, checkout)
33
+ repo = _git_setup(dir)
34
+ repo.checkout checkout, strategy: :force
35
+ end
36
+
37
+ public def find_git_tags(dir)
38
+ repo = _git_setup(dir)
39
+
40
+ # Find all tags
41
+ tags = []
42
+ repo.references.each('refs/tags/*') { |ref| tags << ref }
43
+ tags
44
+ end
45
+
46
+ public def get_git_master_ref(dir)
47
+ repo = _git_setup(dir)
48
+ repo.ref('refs/remotes/origin/master')
49
+ end
50
+ end
@@ -1,9 +1,10 @@
1
1
  require 'colorize'
2
2
  require 'benchmark'
3
+ require 'highline'
3
4
 
4
- module FerretsOnFire::DSL::Logger
5
+ module FerretsOnFire::DSL::LoggerDSL
5
6
  COLORS = {
6
- info: :white,
7
+ info: nil,
7
8
  warn: :yellow,
8
9
  error: :red,
9
10
  success: :green,
@@ -16,7 +17,7 @@ module FerretsOnFire::DSL::Logger
16
17
  warn: '⚠️ ',
17
18
  error: '‼️️ ',
18
19
  success: '✨ ',
19
- question: '',
20
+ question: "\n",
20
21
  action: '⚙️ '
21
22
  }.freeze
22
23
 
@@ -25,7 +26,7 @@ module FerretsOnFire::DSL::Logger
25
26
  warn: '[!]',
26
27
  error: '[X]',
27
28
  success: '[✔]',
28
- question: '[?]',
29
+ question: "\n[?]",
29
30
  action: '[$]'
30
31
  }.freeze
31
32
 
@@ -34,10 +35,15 @@ module FerretsOnFire::DSL::Logger
34
35
  warn: '',
35
36
  error: '',
36
37
  success: '',
37
- question: ' >',
38
+ question: ' > ',
38
39
  action: ''
39
40
  }.freeze
40
41
 
42
+
43
+ public def banner(string, color: :white, background: :black)
44
+ puts string.colorize(color: color, background: background)
45
+ end
46
+
41
47
  # Outputs a info message
42
48
  # @param [String] msg The message
43
49
  public def info(msg)
@@ -68,10 +74,34 @@ module FerretsOnFire::DSL::Logger
68
74
 
69
75
  # Generates a question with the specified msg. If output is true (default) it will be printed.
70
76
  # @param [String] msg The message
71
- # @param [Boolean] output (Optional, default is true). Print the question?
72
- # @return [String] The question
73
- public def question(msg, output = true)
74
- puts log(msg, :question) if output
77
+ # @param [Array<Object>] options Array of option
78
+ # @return [Object] The chosen option value
79
+ public def choose(msg, options, default: nil)
80
+ linebreak
81
+
82
+ HighLine.new.choose do |menu|
83
+ menu.prompt = log(msg + (default.nil? ? '' : " (Default: #{default})"), :question)
84
+ menu.flow = :columns_across
85
+ menu.default = default unless default.nil?
86
+ menu.index_suffix = ') '
87
+
88
+ options.each do |opt|
89
+ menu.choice(opt) { return opt }
90
+ end
91
+ end
92
+ end
93
+
94
+ public def yes_no(msg, default = true)
95
+ answer = nil
96
+
97
+ until answer == '' || answer =~ /^(y|n)$/i
98
+ y = default ? 'Y' : 'y'
99
+ n = default ? 'n' : 'N'
100
+ answer = HighLine.new.ask(log("#{msg} (#{y}/#{n})", :question))
101
+ answer = default ? 'y' : 'n' if answer == ''
102
+ end
103
+
104
+ answer.downcase == 'y'
75
105
  end
76
106
 
77
107
 
@@ -79,21 +109,44 @@ module FerretsOnFire::DSL::Logger
79
109
  puts
80
110
  end
81
111
 
112
+ public def highlight(str)
113
+ str.light_blue
114
+ end
82
115
 
83
- public def crash(msg, output, command: nil, exit_on_failure: true)
116
+
117
+ public def crash(msg, output, command: nil, exit: true)
118
+ puts
84
119
  error msg
85
120
  puts
86
- puts ' ============='
87
- puts "COMMAND: #{command}" unless command.nil?
121
+ puts '=====================[ CRASH REPORT ]====================='.red
122
+
123
+ unless command.nil?
124
+ puts
125
+ puts 'COMMAND: '.red
126
+ puts command
127
+ end
128
+
129
+ puts
130
+ puts 'ERROR:'.red
88
131
  puts output
89
- puts ' ============='
90
132
  puts
91
- exit 1 if exit_on_failure
133
+ puts '=========================================================='.red
134
+ puts
135
+ exit 1 if exit
92
136
  end
93
137
 
94
- # Logs that an action will happen. You have to call action_end after that
138
+ public def action(msg)
139
+ print log(msg, :action)
140
+
141
+ return_value = block_given? ? yield : nil
142
+
143
+ puts "\r#{log(msg, :success)}"
144
+ return_value
145
+ end
146
+
147
+
95
148
  # @param [String] msg Message to display
96
- public def action(msg, &block)
149
+ private def _shell_action(msg)
97
150
  print log(msg, :action, ' ... ')
98
151
  cmd_output = ''
99
152
  bm = ::Benchmark.measure { cmd_output = yield }
@@ -112,6 +165,7 @@ module FerretsOnFire::DSL::Logger
112
165
 
113
166
  info = info.empty? ? '' : "[#{info}] "
114
167
 
115
- "#{prefix} #{info}#{msg}#{suffix}".send(color)
168
+ output = "#{prefix} #{info}#{msg}#{suffix}"
169
+ color.nil? ? output : output.send(color)
116
170
  end
117
171
  end
@@ -1,4 +1,15 @@
1
- module FerretsOnFire::DSL::Shell
1
+ module FerretsOnFire::DSL::ShellDSL
2
+ public def bundle(dir: nil)
3
+ # Set bundler parallel jobs count
4
+ if run('sysctl -n hw.ncpu', quiet: true, return_exit_code: true).zero?
5
+ number_of_cores = run('sysctl -n hw.ncpu', quiet: true).strip.to_i - 1
6
+ run("bundle config --global jobs #{number_of_cores}", quiet: true)
7
+ end
8
+
9
+ run 'bundle', dir: dir, as: 'bundler'
10
+ end
11
+
12
+
2
13
  # Runs a shell command. Stderr is redirected to Stdout
3
14
  # @param [String] cmd Command to run
4
15
  # @param [String] dir Directory to run the command in
@@ -17,23 +28,23 @@ module FerretsOnFire::DSL::Shell
17
28
  cmd = build_command(cmd, dir, rails_env, bundler)
18
29
 
19
30
  # Run the command and print the output if wished
20
- output, status = exec(cmd, quiet, as)
31
+ output, status = execute_shell_cmd(cmd, quiet, as)
21
32
 
22
33
  # Error handling
23
34
  if status.nonzero? && return_exit_code == false
24
- crash "COMMAND EXITED WITH #{status}!", output, command: cmd, exit_on_failure: exit_on_failure
35
+ crash "Shell command exited with status code #{status}!", output, command: cmd, exit_on_failure: exit_on_failure
25
36
  end
26
37
 
27
38
  return_exit_code ? status : output
28
39
  end
29
40
 
30
41
 
31
- # Executes a shell command in the specified dir. Includes benchmarking and debug output.
42
+ # Executes a shell command in the specified dir. Includes benchmarking
32
43
  # @param [String] cmd Command to run
33
44
  # @param [String] quiet Optional. Suppress output
34
45
  # @param [String] label Optional. Label
35
46
  # @return [Array] 0 => output, 1 => exit code
36
- private def exec(cmd, quiet = false, label = nil)
47
+ private def execute_shell_cmd(cmd, quiet = false, label = nil)
37
48
  label ||= cmd
38
49
 
39
50
  # Run the command
@@ -41,7 +52,7 @@ module FerretsOnFire::DSL::Shell
41
52
  cmd_output = `#{cmd} 2>&1`
42
53
  status = $?.to_i
43
54
  else
44
- cmd_output, status = action(label) { `#{cmd} 2>&1` }
55
+ cmd_output, status = _shell_action(label) { `#{cmd} 2>&1` }
45
56
  end
46
57
 
47
58
  # Return exit code and output
@@ -49,7 +60,7 @@ module FerretsOnFire::DSL::Shell
49
60
  end
50
61
 
51
62
 
52
- def build_command(cmd, dir, rails_env, bundler)
63
+ private def build_command(cmd, dir, rails_env, bundler)
53
64
  result = ''
54
65
  result += "cd #{dir} && " unless dir.nil?
55
66
  result += "RAILS_ENV=#{rails_env} " unless rails_env.nil?
@@ -1,15 +1,23 @@
1
1
  module FerretsOnFire::DSL
2
- require 'ferrets_on_fire/dsl/declaration'
3
- require 'ferrets_on_fire/dsl/shell'
4
- require 'ferrets_on_fire/dsl/logger'
5
- require 'ferrets_on_fire/dsl/git'
2
+ require 'ferrets_on_fire/dsl/declaration_dsl'
3
+ require 'ferrets_on_fire/dsl/shell_dsl'
4
+ require 'ferrets_on_fire/dsl/logger_dsl'
5
+ require 'ferrets_on_fire/dsl/git_dsl'
6
6
 
7
- include FerretsOnFire::DSL::Declaration
8
- include FerretsOnFire::DSL::Shell
9
- include FerretsOnFire::DSL::Logger
10
- include FerretsOnFire::DSL::Git
7
+ include FerretsOnFire::DSL::DeclarationDSL
8
+ include FerretsOnFire::DSL::ShellDSL
9
+ include FerretsOnFire::DSL::LoggerDSL
10
+ include FerretsOnFire::DSL::GitDSL
11
11
 
12
12
  public def get(name)
13
13
  @options[name.to_sym] || @global_options[name.to_sym]
14
14
  end
15
+
16
+ public def root
17
+ Bundler.root
18
+ end
19
+
20
+ public def load_lib
21
+ $: << "#{root}/lib"
22
+ end
15
23
  end
@@ -1,3 +1,3 @@
1
1
  module FerretsOnFire
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -2,14 +2,15 @@ module FerretsOnFire
2
2
  require 'ferrets_on_fire/dsl'
3
3
  include FerretsOnFire::DSL
4
4
 
5
- public def execute
6
- @gli = setup_gli
5
+ # FIXME does that work?
6
+ public def call
7
+ @gli = _setup_gli
7
8
  @gli.run(ARGV)
8
9
  exit
9
10
  end
10
11
 
11
12
 
12
- public def setup_gli
13
+ private def _setup_gli
13
14
  GliWrapper.new(@desc, @commands, @options, @switches, @arguments)
14
15
  end
15
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ferrets_on_fire
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
  - phortx
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-24 00:00:00.000000000 Z
11
+ date: 2017-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: micon
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.15'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rugged
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.25'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.25'
69
83
  description: Supercharge your CLI tools. This gem helps you to write powerful CLI
70
84
  tools without caring about the clutter
71
85
  email:
@@ -80,10 +94,10 @@ files:
80
94
  - lib/ferrets_on_fire/argument.rb
81
95
  - lib/ferrets_on_fire/command.rb
82
96
  - lib/ferrets_on_fire/dsl.rb
83
- - lib/ferrets_on_fire/dsl/declaration.rb
84
- - lib/ferrets_on_fire/dsl/git.rb
85
- - lib/ferrets_on_fire/dsl/logger.rb
86
- - lib/ferrets_on_fire/dsl/shell.rb
97
+ - lib/ferrets_on_fire/dsl/declaration_dsl.rb
98
+ - lib/ferrets_on_fire/dsl/git_dsl.rb
99
+ - lib/ferrets_on_fire/dsl/logger_dsl.rb
100
+ - lib/ferrets_on_fire/dsl/shell_dsl.rb
87
101
  - lib/ferrets_on_fire/gli_wrapper.rb
88
102
  - lib/ferrets_on_fire/option.rb
89
103
  - lib/ferrets_on_fire/switch.rb
@@ -1,25 +0,0 @@
1
- module FerretsOnFire::DSL::Git
2
- # Updates the git repository in the current directory and runs bin/update
3
- # @param [String] path The directory to use, default is the current one
4
- public def update_repo(path: nil, desired_branch: nil)
5
- run 'git pull -r --autostash', dir: path, as: 'git pull'
6
-
7
- # get current branch name
8
- if desired_branch
9
- current_branch = run('git branch | grep \*', dir: path, quiet: true).sub('*', '').strip
10
-
11
- unless current_branch == desired_branch
12
- warn "WARNING: Current branch is not #{desired_branch} (it's #{current_branch})"
13
- end
14
- end
15
-
16
- run('bin/update', dir: path, as: 'bin/update', bundler: true) if File.exists?('bin/update')
17
- end
18
-
19
-
20
- public def clone_repo(remote, target: '', desired_branch: 'develop')
21
- run "git clone #{remote} #{target}", as: 'clone'
22
- run "git checkout #{desired_branch}", as: "checkout #{desired_branch}", dir: target
23
- run('bin/setup', dir: target, as: 'bin/setup', bundler: true) if File.exists?('bin/setup')
24
- end
25
- end