xlogin 0.13.9 → 0.13.10

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
  SHA256:
3
- metadata.gz: fb72f536e716a97150265056b54238052e4d551684da2ce925d67239df1a808c
4
- data.tar.gz: 5770c7d59f27dc65c5f5493a91efc5b8a3a83ca299611612f58e1ec745d45204
3
+ metadata.gz: 719819143a56b26ad14b31cbe6e61ed9d4df208c36dc9c060709bce170974d43
4
+ data.tar.gz: e0d20e9e5cd5967cacb28a8d92bd0f342bd5ecf47e591e9b7b3fb6257e6d5690
5
5
  SHA512:
6
- metadata.gz: acbebe02ea2a5f1bb5e4b8d11c5bb847c6a38160f2017a1a078d5e2c19f70cc4f77cbd08370206d208bdbb2f26824fb82e0b1e47450c3b83dce5972fc7d7f815
7
- data.tar.gz: 83a151cae2fe52456b783401f27c1e15e2a97022475d2fe48ba0831ff54b9e95d73241a6a1d4792c4733bb986280adec694710b517536b746e7ca6ba5be3ff4c
6
+ metadata.gz: ce9b1a9bd127b38edd212875887773264019eb25a137eb4f84793b284671915246b2055d5e36c85a0d65d9350910262e642940f5f71d78400e6dffa8addaf4a8
7
+ data.tar.gz: d57ea13b2a0fd0aee2e332cf941e4cf596253297695932944dda3a310932e50be72a9fd0ea099adce2c9784ac55da91c92c781d5b74d3238f418334796eb23f4
data/README.md CHANGED
@@ -62,16 +62,13 @@ Some other commandline options are:
62
62
  ~~~sh
63
63
  $ xlogin -h
64
64
  xlogin HOST_PATTERN [Options]
65
- -i, --inventory PATH The PATH to the inventory file(default: $HOME/.xloginrc).
66
- --template PATH The PATH to the template file.
67
- -T, --template-dir DIRECTORY The DIRECTORY of the template files.
68
- -L, --log-dir [DIRECTORY] The DIRECTORY of the log files(default: $PWD).
69
- -l, --list List all available devices.
70
- -e, --exec Execute commands and quit.
71
- -t, --tty Allocate a pseudo-tty.
72
- -j, --jobs NUM The NUM of jobs to execute in parallel(default: 1).
73
- -E, --enable Try to gain enable priviledge.
74
- -y, --assume-yes Automatically answer yes to any confirmation prompts.
65
+ -i, --inventory PATH The PATH to the inventory file.
66
+ -t, --template PATH The PATH to the template file or directory.
67
+ -L, --log-dir PATH The PATH to the log directory.
68
+ -l, --list List the inventory.
69
+ -e, --exec COMMAND Execute commands and quit.
70
+ -E, --env KEY=VAL Environment variables.
71
+ -j, --jobs NUM The NUM of jobs to execute in parallel.
75
72
  ~~~
76
73
 
77
74
  ## Development
@@ -46,7 +46,7 @@ module Xlogin
46
46
  pool = factory.build_pool(args, **opts)
47
47
 
48
48
  return pool unless block
49
- block.call(pool)
49
+ begin block.call(pool) ensure pool.close end
50
50
  end
51
51
  alias_method :create_pool, :get_pool
52
52
 
@@ -55,8 +55,7 @@ module Xlogin
55
55
  end
56
56
 
57
57
  def settings
58
- @settings ||= {}
59
- @rosettings ||= ReadOnlyStruct.new(@settings)
58
+ ReadOnlyStruct.new(@settings || {})
60
59
  end
61
60
 
62
61
  def generate_templates(dir)
@@ -70,7 +69,7 @@ module Xlogin
70
69
  @factory ||= Xlogin::Factory.instance
71
70
  end
72
71
 
73
- def set(**opts)
72
+ def set(opts = {})
74
73
  @settings ||= {}
75
74
  opts.each do |key, val|
76
75
  val = val.call if val.kind_of?(Proc)
@@ -79,7 +78,7 @@ module Xlogin
79
78
  end
80
79
 
81
80
  def source(*sources, &block)
82
- return factory.instance_eval(&block) if block
81
+ return factory.instance_eval(&block) if block && sources.size == 0
83
82
 
84
83
  sources.each do |path|
85
84
  raise Xlogin::Error.new("Inventory file not found: #{path}") unless File.exist?(path)
@@ -15,13 +15,12 @@ module Xlogin
15
15
  end
16
16
 
17
17
  def list(config)
18
- $stdout.puts Xlogin.list(*config[:pattern]).map { |e| e[:name] }.sort.uniq
18
+ puts Xlogin.list(*config[:pattern]).map { |e| e[:name] }.sort.uniq
19
19
  end
20
20
 
21
21
  def tty(config)
22
- info = Xlogin.list(*config[:pattern]).first
23
- $stdout.puts "Trying #{info[:name]}...", "Escape character is '^]'."
24
-
22
+ info = Xlogin.list(*config[:pattern]).shift
23
+ puts "Trying #{info[:name]}...", "Escape character is '^]'."
25
24
  session, _ = exec(config.merge(pattern: info[:name], jobs: 1))
26
25
  session.interact!
27
26
  end
@@ -44,14 +43,14 @@ module Xlogin
44
43
  loggers << File.expand_path(File.join(config[:"log-dir"], "#{info[:name]}.log"), ENV['PWD']) if config[:"log-dir"]
45
44
 
46
45
  session = Xlogin.get(info.merge(log: loggers))
47
- session.enable(info[:enable]) if config[:enable] && info[:enable]
46
+ session.enable(info[:enable]) if info[:enable] && Xlogin.settings.enable?
48
47
 
49
48
  command_lines = ['', *config[:exec].to_s.split(';').map(&:strip)]
50
49
  command_lines.each { |line| session.cmd(line) }
51
50
 
52
- buffer.string.lines.each { |line| $stdout.print prefix + line.gsub("\r", '') } if jobs > 1
51
+ buffer.string.lines.each { |line| print prefix + line.gsub("\r", '') } if jobs > 1
53
52
  rescue => e
54
- buffer.string.lines.each { |line| $stdout.print prefix + line.gsub("\r", '') } if jobs > 1
53
+ buffer.string.lines.each { |line| print prefix + line.gsub("\r", '') } if jobs > 1
55
54
  raise e
56
55
  end
57
56
 
@@ -61,6 +60,7 @@ module Xlogin
61
60
 
62
61
  def run(args)
63
62
  config = Hash.new
63
+ config[:env] = {}
64
64
  config[:runner] = self.method(:tty)
65
65
  config[:inventory] = DEFAULT_INVENTORY_FILE
66
66
  config[:template] = DEFAULT_TEMPLATE_DIR
@@ -69,23 +69,20 @@ module Xlogin
69
69
  parser.banner = "#{File.basename($0)} HOST_PATTERN [Options]"
70
70
  parser.version = Xlogin::VERSION
71
71
 
72
- parser.on('-i PATH', '--inventory', String, 'The PATH to the inventory file (default: $HOME/.xloginrc).')
73
- parser.on('-T PATH', '--template', String, 'The PATH to the template dir (default: $HOME/.xlogin.d).')
74
- parser.on('-L [DIRECTORY]', '--log-dir', String, 'The PATH to the log dir (default: $PWD).') { |v| v || '.' }
72
+ parser.on('-i PATH', '--inventory', String, 'The PATH to the inventory file.')
73
+ parser.on('-t PATH', '--template', String, 'The PATH to the template file or directory.')
74
+ parser.on('-L PATH', '--log-dir', String, 'The PATH to the log directory.') { |v| v || '.' }
75
75
 
76
- parser.on('-t', '--tty', TrueClass, 'Allocate a pseudo-tty.') { |v| config[:runner] = self.method(:tty) }
77
- parser.on('-l', '--list', TrueClass, 'List the inventory.') { |v| config[:runner] = self.method(:list) }
78
- parser.on('-e COMMAND', '--exec', 'Execute commands and quit.') { |v| config[:runner] = self.method(:exec); v }
76
+ parser.on('-l', '--list', TrueClass, 'List the inventory.') { |v| config[:runner] = self.method(:list) }
77
+ parser.on('-e COMMAND', '--exec', String, 'Execute commands and quit.') { |v| config[:runner] = self.method(:exec); v }
79
78
 
80
- parser.on('-j NUM', '--jobs', Integer, 'The NUM of jobs to execute in parallel(default: 1).')
81
- parser.on('-E', '--enable', TrueClass, 'Try to gain enable priviledge.')
82
- parser.on('-y', '--assume-yes', TrueClass, 'Automatically answer yes to prompts.')
79
+ parser.on('-E KEY=VAL', '--env', /(\w+=\w+)+/, 'Environment variables.')
80
+ parser.on('-j NUM', '--jobs', Integer, 'The NUM of jobs to execute in parallel.')
83
81
 
84
- parser.parse!(args, into: config)
85
- config[:pattern] = args
82
+ config[:pattern] = parser.parse!(args, into: config)
86
83
 
87
84
  Xlogin.configure do
88
- set assume_yes: true if config[:assume_yes]
85
+ set Hash[config[:env].map{ |v| v.split('=') }]
89
86
  source File.expand_path(config[:inventory], ENV['PWD'])
90
87
  template File.expand_path(config[:template], ENV['PWD'])
91
88
  end
@@ -6,7 +6,7 @@ module Xlogin
6
6
 
7
7
  DEFAULT_TIMEOUT = 10
8
8
  DEFAULT_PROMPT = /[$%#>] ?\z/n
9
- RESERVED_METHODS = %i( login logout enable disable delegate )
9
+ RESERVED_METHODS = %i( login logout enable disable )
10
10
 
11
11
  attr_reader :name, :scopes, :methods
12
12
 
@@ -1,3 +1,3 @@
1
1
  module Xlogin
2
- VERSION = "0.13.9"
2
+ VERSION = "0.13.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xlogin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.9
4
+ version: 0.13.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - haccht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-04 00:00:00.000000000 Z
11
+ date: 2020-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-telnet
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  requirements: []
196
- rubygems_version: 3.0.0
196
+ rubygems_version: 3.0.3
197
197
  signing_key:
198
198
  specification_version: 4
199
199
  summary: rancid clogin alternative