hammer_cli 0.15.0 → 0.15.1

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: aaf3be9933ac2bf33cd6a7bd3cd0f3d8fe3bf157
4
- data.tar.gz: 3fd10d78572c35d887f0edc9b46d4382e4454006
3
+ metadata.gz: 3fdeba3063ee3ba211aabb8a6d57d17a70fb7f22
4
+ data.tar.gz: b085e64553cde11ebed24c0525e461bdcf9ee3e0
5
5
  SHA512:
6
- metadata.gz: 3f18891b02bd45efcddf967b97bc74b58a277c28cfa8d0d22e4e339ecb9f876565e111cdc9bf670d4f122ae68cf858f398a067c75daf147b694de98573947b62
7
- data.tar.gz: e9dee591bf84da08b467a36f155c97068951d9937e128fbb2d7b42d97af1fdd7f03040321daf5457472d66ddba55fb8677981e6180695ee130bfb1f20c32f8ce
6
+ metadata.gz: 9a706bd9e66688c5642575c9eea4d3d5963847eb93dcac2293b14a3d109d3d52582effa20dd9f69c51448a5497e1555ed769759c58ce9a84b1d70ea96711a2b1
7
+ data.tar.gz: 967e76b9ee2e0ed6f131b5dced17032bfe288f9e74ac7e831dc92865b0478ee2b5056a6edcae41064e97d0c36092932529bfa07d0fe6002514dde1e8a28ca0ee
data/bin/hammer CHANGED
@@ -13,6 +13,7 @@ require 'hammer_cli/options/normalizers'
13
13
  # Option descriptions are never displayed and thus do not require translation.
14
14
  class PreParser < Clamp::Command
15
15
  option ['-v', '--[no-]verbose'], :flag, _('Be verbose (or not). True by default')
16
+ option ['--[no-]use-defaults'], :flag, _('Enable/disable stored defaults. Enabled by default')
16
17
  option ['-q', '--quiet'], :flag, _('Completely silent')
17
18
  option ["-d", "--debug"], :flag, "show debugging output"
18
19
  option ["-c", "--config"], "CFG_FILE", "path to custom config file" do |path|
@@ -92,6 +93,8 @@ HammerCLI::Settings.load({
92
93
  :ssl_with_basic_auth => preparser.ssl_with_basic_auth?
93
94
  }})
94
95
 
96
+ HammerCLI::Settings.load({:use_defaults => preparser.use_defaults?}) unless preparser.use_defaults?.nil?
97
+
95
98
  if HammerCLI::Settings.get(:ui, :mark_translated)
96
99
  include HammerCLI::I18n::Debug
97
100
  end
@@ -32,6 +32,9 @@
32
32
  # 2 - data, messages, interactive I/O, progress bars. Equals to --verbose.
33
33
  :verbosity: 2
34
34
 
35
+ # Enable/disable defaults. Preset default values for the options won't be used.
36
+ #:use_defaults: true
37
+
35
38
  #:log_owner: 'foreman'
36
39
  #:log_group: 'foreman'
37
40
 
@@ -1,6 +1,10 @@
1
1
  Release notes
2
2
  =============
3
- ### 0.14.0 (2018-10-24)
3
+ ### 0.15.1 (2018-11-06)
4
+ * Helper for editing text in editor ([PR #294](https://github.com/theforeman/hammer-cli/pull/294)) ([#24489](http://projects.theforeman.org/issues/24489))
5
+ * Add ability to disable defaults ([PR #293](https://github.com/theforeman/hammer-cli/pull/293)) ([#25307](http://projects.theforeman.org/issues/25307))
6
+
7
+ ### 0.15.0 (2018-10-24)
4
8
  * Correct the gemspec ([PR #286](https://github.com/theforeman/hammer-cli/pull/286))
5
9
  * Use the tty for the interactive output ([PR #289](https://github.com/theforeman/hammer-cli/pull/289)) ([#6935](http://projects.theforeman.org/issues/6935))
6
10
  * Remove legacy code for ruby < 2.0 ([#21359](http://projects.theforeman.org/issues/21359))
@@ -245,10 +245,9 @@ module HammerCLI
245
245
 
246
246
 
247
247
  def option_sources
248
- [
249
- HammerCLI::Options::Sources::CommandLine.new(self),
250
- HammerCLI::Options::Sources::SavedDefaults.new(context[:defaults], logger)
251
- ]
248
+ sources = [HammerCLI::Options::Sources::CommandLine.new(self)]
249
+ sources << HammerCLI::Options::Sources::SavedDefaults.new(context[:defaults], logger) if context[:use_defaults]
250
+ sources
252
251
  end
253
252
 
254
253
  private
@@ -7,6 +7,7 @@ module HammerCLI
7
7
  :is_tty? => HammerCLI.tty?,
8
8
  :api_connection => HammerCLI::Connection.new(Logging.logger['Connection']),
9
9
  :no_headers => HammerCLI::Settings.get(:ui, :no_headers),
10
+ :use_defaults => HammerCLI::Settings.get(:use_defaults),
10
11
  :capitalization => HammerCLI.capitalization,
11
12
  :verbosity => (HammerCLI::Settings.get(:verbosity) || HammerCLI::V_VERBOSE).to_i
12
13
  }
@@ -9,7 +9,6 @@ module HammerCLI
9
9
  attr_reader :defaults_settings
10
10
 
11
11
  def initialize(settings, file_path = nil)
12
-
13
12
  @defaults_settings = settings || {}
14
13
  @path = file_path || DEFAULT_FILE
15
14
  end
@@ -100,8 +99,7 @@ module HammerCLI
100
99
  end
101
100
 
102
101
  def self.defaults
103
- @defaults ||= Defaults.new(HammerCLI::Settings.settings[:defaults])
104
-
102
+ @defaults ||= Defaults.new(HammerCLI::Settings.get(:defaults))
105
103
  end
106
104
 
107
105
  HammerCLI::MainCommand.subcommand "defaults", _("Defaults management"), HammerCLI::DefaultsCommand
@@ -10,6 +10,7 @@ module HammerCLI
10
10
  option ['-q', '--quiet'], :flag, _('Completely silent') do
11
11
  context[:verbosity] = HammerCLI::V_QUIET
12
12
  end
13
+ option ['--[no-]use-defaults'], :flag, _('Enable/disable stored defaults. Enabled by default')
13
14
  option ["-d", "--debug"], :flag, _("Show debugging output"), :context_target => :debug
14
15
  option ["-r", "--reload-cache"], :flag, _("Force reload of Apipie cache")
15
16
 
@@ -46,6 +46,11 @@ module HammerCLI
46
46
  end
47
47
 
48
48
  def self.clear
49
+ empty
50
+ load(default_settings)
51
+ end
52
+
53
+ def self.empty
49
54
  settings.clear
50
55
  path_history.clear
51
56
  end
@@ -59,9 +64,16 @@ module HammerCLI
59
64
  @path_history
60
65
  end
61
66
 
67
+ def self.default_settings
68
+ {
69
+ :use_defaults => true
70
+ }
71
+ end
72
+
62
73
  private
74
+
63
75
  def self.settings
64
- @settings_hash ||= {}
76
+ @settings_hash ||= default_settings
65
77
  @settings_hash
66
78
  end
67
79
 
@@ -1,4 +1,5 @@
1
1
  require 'highline'
2
+ require 'tempfile'
2
3
 
3
4
  class String
4
5
  def format(params)
@@ -84,4 +85,15 @@ module HammerCLI
84
85
  def self.interactive_output
85
86
  @interactive_output ||= HighLine.new($stdin, IO.new(IO.sysopen('/dev/tty', 'w'), 'w'))
86
87
  end
88
+
89
+ def self.open_in_editor(content, content_type: '', tempdir: '/tmp', suffix: '.tmp')
90
+ result = content
91
+ Tempfile.open([content_type, suffix], tempdir) do |f|
92
+ f.write(content)
93
+ f.rewind
94
+ system("#{ENV['EDITOR'] || 'vi'} #{f.path}")
95
+ result = f.read
96
+ end
97
+ result
98
+ end
87
99
  end
@@ -1,5 +1,5 @@
1
1
  module HammerCLI
2
2
  def self.version
3
- @version ||= Gem::Version.new '0.15.0'
3
+ @version ||= Gem::Version.new '0.15.1'
4
4
  end
5
5
  end
@@ -373,7 +373,8 @@ describe HammerCLI::AbstractCommand do
373
373
  before do
374
374
  @defaults = mock()
375
375
  @defaults.stubs(:get_defaults).returns(nil)
376
- @cmd = TestDefaultsCmd.new("", { :defaults => @defaults })
376
+ @cmd = TestDefaultsCmd.new("", { :defaults => @defaults, :use_defaults => true })
377
+ @cmd_no_defaults = TestDefaultsCmd.new("", { :defaults => @defaults, :use_defaults => false })
377
378
  end
378
379
 
379
380
  it 'provides default value for an option flag' do
@@ -381,6 +382,11 @@ describe HammerCLI::AbstractCommand do
381
382
  assert_equal({'different_attr_name' => 2}, @cmd.options)
382
383
  end
383
384
 
385
+ it 'does not set default value if the defaults are disabled' do
386
+ @defaults.expects(:get_defaults).never()
387
+ assert_equal({}, @cmd_no_defaults.options)
388
+ end
389
+
384
390
  it 'prefers values from command line' do
385
391
  @defaults.stubs(:get_defaults).with('--test').returns(2)
386
392
  @cmd.run(['--test=1'])
@@ -44,6 +44,7 @@ describe HammerCLI::Settings do
44
44
  end
45
45
 
46
46
  it "dumps all settings" do
47
+ settings.empty
47
48
  data = {:a => 1, :b => 2}
48
49
  settings.load(data)
49
50
  settings.dump.must_equal data
@@ -69,11 +70,23 @@ describe HammerCLI::Settings do
69
70
  settings.get(:x).size.must_equal 4
70
71
  end
71
72
 
72
- it "clear wipes all settings" do
73
+ it "clear wipes all settings but default values" do
73
74
  settings.load({:a => 1, :b => 2})
74
75
  settings.clear
75
76
  settings.get(:a).must_be_nil
76
77
  settings.get(:b).must_be_nil
78
+ settings.default_settings.each { |key, val| settings.get(key).must_equal val }
79
+ end
80
+
81
+ it "empty wipes all settings including default values" do
82
+ settings.load({:a => 1, :b => 2})
83
+ settings.empty
84
+ settings.dump.must_equal({})
85
+ end
86
+
87
+ it "initializes settings with default settings" do
88
+ settings.instance_variable_set(:@settings_hash, nil)
89
+ settings.dump.must_equal settings.default_settings
77
90
  end
78
91
 
79
92
  context "load from paths" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hammer_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Bačovský
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-10-24 00:00:00.000000000 Z
12
+ date: 2018-11-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: clamp