ranch-hand 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +9 -1
- data/bin/ranch-hand +15 -2
- data/files/ranch-hand.plugin.zsh +6 -4
- data/lib/ranch_hand/base.rb +6 -0
- 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 +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e00a609606b6a4c9fab740093f660f8de3b4a655cbe8d3ab23a381d6cb26be97
|
4
|
+
data.tar.gz: fe56f11021d0a8ed6e68231bf7096cbc06b053ee02341a7ce53d369f63d92db1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 876144c9dc6339c290eb167e6d5f9a3eb29f73b1188e210b9e362eea27b60abcb6c5f6fb881d65b98751b865b2efde82103b4b510ce0f180fec1be1a326d7cb8
|
7
|
+
data.tar.gz: c7ef6622566ab70f3f8765b6d4efb86c8c0380ecd80dcfd049ae1c3b5d4c5ac4a20bec5a5855bf27280fb0ad281b2b87a298e6eda3687e632c0d9206c8b2ab92
|
data/Changelog.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
### 0.8.0
|
2
|
+
- 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)
|
3
|
+
- Add ability to edit the project config file via new command `ranch-hand update_config` (peregrinator/ranch-hand/issues/9)
|
4
|
+
- Add ohmyzsh aliases for new commands
|
5
|
+
### 0.7.1
|
6
|
+
Add Oh My Zsh plugin to provide shortcuts, see files/ranch-hand.plugin.zsh
|
7
|
+
Add new `ranch-hand ohmyzsh` command to install plugins
|
8
|
+
|
1
9
|
### 0.7.0
|
2
10
|
#### Features
|
3
11
|
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.
|
@@ -10,4 +18,4 @@ Add support for command arguments. Commands that use arguments no longer need to
|
|
10
18
|
### 0.6.0
|
11
19
|
|
12
20
|
Updates for Ruby 3.0 compat
|
13
|
-
- https://rubyreferences.github.io/rubychanges/3.0.html#keyword-arguments-are-now-fully-separated-from-positional-arguments
|
21
|
+
- https://rubyreferences.github.io/rubychanges/3.0.html#keyword-arguments-are-now-fully-separated-from-positional-arguments
|
data/bin/ranch-hand
CHANGED
@@ -30,13 +30,20 @@ module RanchHandCLI
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
desc 'Initializes ranch hand for project'
|
33
|
+
desc 'Initializes ranch hand for current project'
|
34
34
|
command :init do |c|
|
35
35
|
c.action do |global_options, command_options, args|
|
36
36
|
RanchHand::Base.init
|
37
37
|
end
|
38
38
|
end
|
39
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
|
+
|
40
47
|
desc 'Execs into a running container'
|
41
48
|
command :exec do |c|
|
42
49
|
config = RanchHand::Config.load
|
@@ -44,14 +51,20 @@ module RanchHandCLI
|
|
44
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."
|
45
52
|
c.switch [:rm, :remove], negatable: false, desc: "Used to indicated that you want to remove a previously saved command."
|
46
53
|
c.switch [:r, :repeat], negatable: false, desc: "Repeat the last command ran (against the same pod)."
|
54
|
+
c.switch [:sp, :skip_prefix], negatable: false, default_value: false, desc: "Do not add configured command prefix."
|
47
55
|
|
48
56
|
c.flag [:c, :command], desc: "Command to run once (not permanently stored)"
|
49
57
|
c.flag [:f, :filter], desc: "Filter pods returned to those that contain the string provided (negative matches supported). Examples: '-f nginx', '-f -apache'"
|
50
58
|
c.flag [:n, :namespace], required: true, default_value: config[:namespace], desc: "Namespace against which to retreive pods and run command"
|
51
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"
|
52
60
|
|
61
|
+
default_command_options = {
|
62
|
+
command_prefix: config[:command_prefix],
|
63
|
+
prefer_ui: config[:prefer_ui]
|
64
|
+
}
|
65
|
+
|
53
66
|
c.action do |global_options, command_options, args|
|
54
|
-
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))
|
55
68
|
end
|
56
69
|
end
|
57
70
|
|
data/files/ranch-hand.plugin.zsh
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
alias rh='ranch-hand'
|
2
|
-
alias rhs='ranch-hand setup'
|
3
|
-
alias rhi='ranch-hand init'
|
4
|
-
alias
|
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
@@ -34,5 +34,11 @@ module RanchHand
|
|
34
34
|
RanchHand::Logger.info("installation complete")
|
35
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
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
|
37
43
|
end
|
38
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.0
|
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
|