ranch-hand 0.7.0 → 0.8.1
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 +4 -4
- data/Changelog.md +20 -1
- data/bin/ranch-hand +23 -3
- data/files/ranch-hand.plugin.zsh +6 -0
- data/lib/ranch_hand/base.rb +29 -1
- data/lib/ranch_hand/commands.rb +1 -1
- data/lib/ranch_hand/config.rb +34 -7
- data/lib/ranch_hand/constants.rb +1 -1
- data/lib/ranch_hand/kube_ctl.rb +15 -12
- data/lib/ranch_hand/logger.rb +1 -1
- data/lib/ranch_hand/storage.rb +1 -1
- data/lib/ranch_hand/version.rb +1 -1
- data/lib/ranch_hand.rb +2 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fb14b44db08c6e28ef1ff0e3af33dac5d59db3796b258a335d97e2877a0f8d9
|
4
|
+
data.tar.gz: 2f511a77fc5e745c0dd82669e45994be770bd459e362c71023a3c3cf61261de5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6144eaf7a166690fa432663ff327d07039a587ccbb0273ab48d05cb05210a89296821ff1720f7050aa2d06274b00216774d2b437551e64cfa1ba46e873e10d6
|
7
|
+
data.tar.gz: 4607f82b622d699f95ca94ad21fe0b82a8b8ff9a172f164731dc5e4ea43939ced13ad80e472f0c1f138b6eb5d6806a0157819c2486538363952ad1359df48cf1
|
data/Changelog.md
CHANGED
@@ -1,4 +1,23 @@
|
|
1
|
+
### 0.8.1
|
2
|
+
- Bug fix for ohmyzsh shortcut that used wrong flag for skip prefix
|
3
|
+
### 0.8.0
|
4
|
+
- Add ability to specify a command prefix that will be added to all commands run via `ranch-hand exec` by default (peregrinator/ranch-hand/issues/8)
|
5
|
+
- Add ability to edit the project config file via new command `ranch-hand update_config` (peregrinator/ranch-hand/issues/9)
|
6
|
+
- Add ohmyzsh aliases for new commands
|
7
|
+
### 0.7.1
|
8
|
+
Add Oh My Zsh plugin to provide shortcuts, see files/ranch-hand.plugin.zsh
|
9
|
+
Add new `ranch-hand ohmyzsh` command to install plugins
|
10
|
+
|
11
|
+
### 0.7.0
|
12
|
+
#### Features
|
13
|
+
Add support for command arguments. Commands that use arguments no longer need to be wrapped in a string in order to be passed properly. This provides a better interface for editor plugins that automatically append arguments to the end of a custom command.
|
14
|
+
- https://github.com/peregrinator/ranch-hand/commit/a70d44042507d407c0088a2a8ffa4d4514a800af
|
15
|
+
- ex: before: `ranch-hand exec -c 'rspec spec/foo.rb:21'`, now: `ranch-hand exec -c rspec spec/foo.rb:21`
|
16
|
+
|
17
|
+
#### Bugfixes:
|
18
|
+
- d76855: correctly handle scenario in which the namespace queried has no pods
|
19
|
+
|
1
20
|
### 0.6.0
|
2
21
|
|
3
22
|
Updates for Ruby 3.0 compat
|
4
|
-
- https://rubyreferences.github.io/rubychanges/3.0.html#keyword-arguments-are-now-fully-separated-from-positional-arguments
|
23
|
+
- https://rubyreferences.github.io/rubychanges/3.0.html#keyword-arguments-are-now-fully-separated-from-positional-arguments
|
data/bin/ranch-hand
CHANGED
@@ -23,13 +23,27 @@ module RanchHandCLI
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
desc '
|
26
|
+
desc 'Installs ranch hand Oh My Zsh shortcuts'
|
27
|
+
command :ohmyzsh do |c|
|
28
|
+
c.action do |global_options, options, args|
|
29
|
+
RanchHand::Base.install_ohmyzsh
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'Initializes ranch hand for current project'
|
27
34
|
command :init do |c|
|
28
35
|
c.action do |global_options, command_options, args|
|
29
36
|
RanchHand::Base.init
|
30
37
|
end
|
31
38
|
end
|
32
39
|
|
40
|
+
desc 'Updates ranch hand config for current project'
|
41
|
+
command :update_config do |c|
|
42
|
+
c.action do |global_options, command_options, args|
|
43
|
+
RanchHand::Base.update_config
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
33
47
|
desc 'Execs into a running container'
|
34
48
|
command :exec do |c|
|
35
49
|
config = RanchHand::Config.load
|
@@ -37,14 +51,20 @@ module RanchHandCLI
|
|
37
51
|
c.switch [:g, :group], negatable: true, default_value: config[:group] || false, desc: "Group pods returned so that there is only one from each deployment, --no-group can be used to override project config as needed."
|
38
52
|
c.switch [:rm, :remove], negatable: false, desc: "Used to indicated that you want to remove a previously saved command."
|
39
53
|
c.switch [:r, :repeat], negatable: false, desc: "Repeat the last command ran (against the same pod)."
|
40
|
-
|
54
|
+
c.switch [:sp, :skip_prefix], negatable: false, default_value: false, desc: "Do not add configured command prefix."
|
55
|
+
|
41
56
|
c.flag [:c, :command], desc: "Command to run once (not permanently stored)"
|
42
57
|
c.flag [:f, :filter], desc: "Filter pods returned to those that contain the string provided (negative matches supported). Examples: '-f nginx', '-f -apache'"
|
43
58
|
c.flag [:n, :namespace], required: true, default_value: config[:namespace], desc: "Namespace against which to retreive pods and run command"
|
44
59
|
c.flag [:p, :pod], default_value: config[:pod], desc: "Run command in a specific pod. If used with -g only the pod name can be specified and the command will be run against the first in the group"
|
45
60
|
|
61
|
+
default_command_options = {
|
62
|
+
command_prefix: config[:command_prefix],
|
63
|
+
prefer_ui: config[:prefer_ui]
|
64
|
+
}
|
65
|
+
|
46
66
|
c.action do |global_options, command_options, args|
|
47
|
-
RanchHand::KubeCtl.new.exec(args: args, cmd_options: command_options)
|
67
|
+
RanchHand::KubeCtl.new.exec(args: args, cmd_options: default_command_options.merge(command_options))
|
48
68
|
end
|
49
69
|
end
|
50
70
|
|
@@ -0,0 +1,6 @@
|
|
1
|
+
alias rh='ranch-hand' # main binary alias
|
2
|
+
alias rhs='ranch-hand setup' # setup ranch hand with Rancher CLI credentials
|
3
|
+
alias rhi='ranch-hand init' # initialize default ranch hand settings in a project
|
4
|
+
alias rhu='ranch-hand update_config' # update default ranch hand settings for a project
|
5
|
+
alias rhe='ranch-hand exec' # run a command in a container
|
6
|
+
alias rhes='ranch-hand exec --skip_prefix' # run a command in a container but skip default command_prefix
|
data/lib/ranch_hand/base.rb
CHANGED
@@ -12,5 +12,33 @@ module RanchHand
|
|
12
12
|
RanchHand::Config.create
|
13
13
|
RanchHand::Logger.info("initialization complete")
|
14
14
|
end
|
15
|
+
|
16
|
+
def self.install_ohmyzsh
|
17
|
+
RanchHand::Logger.info("installing ranch-hand Oh My Zsh shortcuts")
|
18
|
+
|
19
|
+
unless ENV['ZSH_CUSTOM'] || ENV['ZSH']
|
20
|
+
RanchHand::Logger.warn("Could not find $ZSH_CUSTOM or $ZSH in your environment, can not install shortcuts")
|
21
|
+
return
|
22
|
+
end
|
23
|
+
|
24
|
+
zsh_custom_dir = ENV['ZSH_CUSTOM'] || File.join(ENV['ZSH'], 'custom')
|
25
|
+
|
26
|
+
zsh_plugin_dir = File.join(zsh_custom_dir, 'plugins', 'ranch-hand')
|
27
|
+
FileUtils.mkdir_p(zsh_plugin_dir)
|
28
|
+
|
29
|
+
current_path = File.expand_path(File.dirname(__FILE__))
|
30
|
+
gem_plugin_path = File.join(current_path, '..', '..', 'files', 'ranch-hand.plugin.zsh')
|
31
|
+
|
32
|
+
FileUtils.cp(gem_plugin_path, zsh_plugin_dir)
|
33
|
+
|
34
|
+
RanchHand::Logger.info("installation complete")
|
35
|
+
RanchHand::Logger.info("Don't forget to add 'ranch-hand' to your plugins in ~/.zshrc -- e.g. plugins=(ranch-hand) -- and then 'source ~/.zshrc'")
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.update_config
|
39
|
+
RanchHand::Logger.info("updating ranch-hand config for project")
|
40
|
+
RanchHand::Config.update
|
41
|
+
RanchHand::Logger.info("update complete")
|
42
|
+
end
|
15
43
|
end
|
16
|
-
end
|
44
|
+
end
|
data/lib/ranch_hand/commands.rb
CHANGED
data/lib/ranch_hand/config.rb
CHANGED
@@ -15,24 +15,51 @@ module RanchHand
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
def self.update
|
19
|
+
save(generate_config(load))
|
20
|
+
end
|
21
|
+
|
18
22
|
private
|
19
23
|
|
20
|
-
def self.generate_config
|
24
|
+
def self.generate_config(current={})
|
25
|
+
unless current.empty?
|
26
|
+
puts "Current config:"
|
27
|
+
pp current
|
28
|
+
puts "A blank entry to the following prompts will keep the current config value."
|
29
|
+
end
|
30
|
+
|
21
31
|
namespace = prompt.ask('Namespace:')
|
22
32
|
group = prompt.ask('Use group command by default? (Y/n):')
|
23
|
-
group = %w(n N).include?(group) ? false : true
|
24
33
|
pod = prompt.ask('Pod name:')
|
34
|
+
prefix = prompt.ask('Command prefix (optional):')
|
25
35
|
|
26
|
-
|
36
|
+
# set default value if there is no current or entered value
|
37
|
+
if group.nil? && current[:group].nil?
|
38
|
+
group = %w(n N).include?(group) ? false : true
|
39
|
+
end
|
40
|
+
|
41
|
+
# if command prefix is provided set prefer_ui to false
|
42
|
+
# prefer_ui skips the #exec command line ui if set to true
|
43
|
+
# this supports a base case where the prefix command is the
|
44
|
+
# only command the user wants to run (eg. simple connection to the pod)
|
45
|
+
if current[:prefer_ui]
|
46
|
+
prefer_ui = nil
|
47
|
+
elsif prefix || current[:command_prefix]
|
48
|
+
prefer_ui = false
|
49
|
+
else
|
50
|
+
prefer_ui = true
|
51
|
+
end
|
52
|
+
|
53
|
+
current.merge({
|
54
|
+
command_prefix: prefix,
|
27
55
|
group: group,
|
28
56
|
namespace: namespace,
|
29
|
-
pod: pod
|
30
|
-
|
57
|
+
pod: pod,
|
58
|
+
prefer_ui: prefer_ui
|
59
|
+
}.compact)
|
31
60
|
end
|
32
61
|
|
33
62
|
def self.save(config)
|
34
|
-
# File.new(project_config_path, 'w+', 0640)
|
35
|
-
|
36
63
|
File.open(project_config_path, 'w', 0640) do |f|
|
37
64
|
f.write(config.to_yaml)
|
38
65
|
end
|
data/lib/ranch_hand/constants.rb
CHANGED
data/lib/ranch_hand/kube_ctl.rb
CHANGED
@@ -6,19 +6,27 @@ module RanchHand
|
|
6
6
|
args = Array(args)
|
7
7
|
|
8
8
|
namespace = cmd_options.delete(:namespace)
|
9
|
-
|
9
|
+
|
10
10
|
if cmd_options[:remove]
|
11
11
|
remove_command(namespace)
|
12
12
|
elsif cmd_options[:repeat]
|
13
13
|
repeat_command(namespace)
|
14
|
-
elsif cmd_options[:command]
|
14
|
+
elsif cmd_options[:command] || (!cmd_options[:prefer_ui] && cmd_options[:command_prefix])
|
15
15
|
pod = select_pod(namespace, cmd_options)
|
16
|
-
run_command(namespace, pod, cmd_options
|
16
|
+
run_command(namespace, pod, generate_command(cmd_options), args)
|
17
17
|
else
|
18
18
|
choose_command(namespace, cmd_options)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
def generate_command(cmd_options)
|
23
|
+
if cmd_options[:skip_prefix]
|
24
|
+
command = cmd_options[:command]
|
25
|
+
else
|
26
|
+
command = "#{cmd_options[:command_prefix]} #{cmd_options[:command]}".strip
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
22
30
|
def run_command(namespace, pod, cmd, args=[])
|
23
31
|
system("rancher kubectl -n #{namespace} exec -it #{pod} -- #{cmd} #{args.join(' ')}".strip)
|
24
32
|
end
|
@@ -26,7 +34,7 @@ module RanchHand
|
|
26
34
|
def choose_command(namespace, options={})
|
27
35
|
pod = select_pod(namespace, options)
|
28
36
|
type, cmd = select_command(namespace, pod)
|
29
|
-
|
37
|
+
|
30
38
|
run_command(namespace, pod, cmd)
|
31
39
|
end
|
32
40
|
|
@@ -59,9 +67,9 @@ module RanchHand
|
|
59
67
|
|
60
68
|
if options[:filter]
|
61
69
|
if options[:filter].start_with?('-')
|
62
|
-
pods = pods.reject{|p| p.match?(/#{options[:filter][1..-1]}/)}
|
70
|
+
pods = pods.reject{|p| p.match?(/#{options[:filter][1..-1]}/)}
|
63
71
|
else
|
64
|
-
pods = pods.select{|p| p.match?(/#{options[:filter]}/)}
|
72
|
+
pods = pods.select{|p| p.match?(/#{options[:filter]}/)}
|
65
73
|
end
|
66
74
|
end
|
67
75
|
prompt.error("No pods matching filter: '#{options[:filter]}'") and exit if pods.empty?
|
@@ -183,10 +191,5 @@ module RanchHand
|
|
183
191
|
def storage
|
184
192
|
@storage ||= RanchHand::Storage.new
|
185
193
|
end
|
186
|
-
|
187
|
-
# def project_config
|
188
|
-
# project_config_file = File.join(Dir.pwd, ".ranch-hand")
|
189
|
-
# YAML.load_file(project_config_file) || {}
|
190
|
-
# end
|
191
194
|
end
|
192
|
-
end
|
195
|
+
end
|
data/lib/ranch_hand/logger.rb
CHANGED
data/lib/ranch_hand/storage.rb
CHANGED
data/lib/ranch_hand/version.rb
CHANGED
data/lib/ranch_hand.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# stdlib
|
2
2
|
require 'fileutils'
|
3
3
|
require 'logger'
|
4
|
+
require 'pp'
|
4
5
|
require 'yaml'
|
5
6
|
|
6
7
|
# gems
|
@@ -15,4 +16,4 @@ require 'ranch_hand/constants.rb'
|
|
15
16
|
require 'ranch_hand/kube_ctl.rb'
|
16
17
|
require 'ranch_hand/logger.rb'
|
17
18
|
require 'ranch_hand/storage.rb'
|
18
|
-
require 'ranch_hand/version.rb'
|
19
|
+
require 'ranch_hand/version.rb'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ranch-hand
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peregrinator
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- bin/ranch-hand
|
130
130
|
- bin/setup
|
131
131
|
- doc/ranch-hand-demo.gif
|
132
|
+
- files/ranch-hand.plugin.zsh
|
132
133
|
- lib/ranch_hand.rb
|
133
134
|
- lib/ranch_hand/base.rb
|
134
135
|
- lib/ranch_hand/commands.rb
|
@@ -158,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
159
|
- !ruby/object:Gem::Version
|
159
160
|
version: '0'
|
160
161
|
requirements: []
|
161
|
-
rubygems_version: 3.2.
|
162
|
+
rubygems_version: 3.2.22
|
162
163
|
signing_key:
|
163
164
|
specification_version: 4
|
164
165
|
summary: Provides an interface between the Rancher CLI and the Kubectl commands
|