hammer_cli_foreman_tasks 0.0.25 → 0.1.0

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: 0d28037aaaca062b487102f190490a7238916f4439d37d8f99d689f1c19acfdd
4
- data.tar.gz: c62de4cb043b1ffd46fad42acfc08fb6ad6fb38aae5476768d1718f615fbf101
3
+ metadata.gz: 1268600e04f2e953de0d5f813e855d9873632c64b300b9725c9576698e243c5d
4
+ data.tar.gz: 2f3a62ca2949ac6e16c9b0fe72e6960da7df6c96c79598e00163c61bf23e3fb0
5
5
  SHA512:
6
- metadata.gz: 4bf35322200ad65b8dfe6f22f3dfccb701a6d968a6271925cdb2c716914a3206fcdbaffa78346624a8c825983a53164e3f944f6d6f8b2a9d96dc953e6672ebd3
7
- data.tar.gz: e2b56f6d61c37191904cd0302286479cd007949f7ef67f72d411f7a01c8ced3e1fceb8ff102578bcf3d795d0cbfe5f597c1b43cd8ab1f0f7cecf0ba2fc85ca56
6
+ metadata.gz: a21a6d1e54cc9c1baa931cee2d6aed2d74441081b90b8bf59d9380a38a073fa17bafc02a73e77700efe8efcc8d7722996892dcbe9c0c81dfa5d0589175497bd5
7
+ data.tar.gz: ab7bd9ca157a8246abd49549a0620d5e854fe358a53383ecd43b39884da4eb1da1b66477ddb52e3a1d33bcdece33c4c2874cac0731c9f6712842500d713c5285
@@ -1,21 +1,15 @@
1
- require 'date'
2
-
3
1
  module HammerCLIForemanTasks
4
2
  module CommandExtensions
5
3
  class RecurringLogic < HammerCLI::CommandExtensions
6
4
  before_print do |data|
7
- data['action'] = format_task_input(data['tasks'].last)
8
- data['last_occurrence'] = recurring_logic_last_occurrence(data)
9
- data['next_occurrence'] = recurring_logic_next_occurrence(data)
10
- data['iteration_limit'] = format_recurring_logic_limit(data['max_iteration'])
11
- data['repeat_until'] = format_recurring_logic_limit(data['end_time'])
5
+ records(data).each { |record| format_record(record) }
12
6
  end
13
7
 
14
8
  output do |definition|
15
9
  definition.insert(:after, :cron_line) do
16
- field :action, _('Action')
17
- field :last_occurrence, _('Last occurrence')
18
- field :next_occurrence, _('Next occurrence')
10
+ field :action, _('Action'), nil, hide_blank: true
11
+ field :last_occurrence, _('Last occurrence'), Fields::Date, hide_blank: true
12
+ field :next_occurrence, _('Next occurrence'), Fields::Date, hide_blank: true
19
13
  end
20
14
  definition.insert(:after, :iteration) do
21
15
  field :iteration_limit, _('Iteration limit')
@@ -25,26 +19,27 @@ module HammerCLIForemanTasks
25
19
  end
26
20
  end
27
21
 
28
- def self.recurring_logic_last_occurrence(recurring_logic)
29
- last_task = recurring_logic['tasks'].select { |t| t['started_at'] }
30
- .max { |a, b| a['started_at'] <=> b['started_at'] }
31
- return '-' if last_task.nil? || last_task['started_at'].nil?
32
-
33
- last_task['started_at']
34
- end
35
-
36
- def self.recurring_logic_next_occurrence(recurring_logic)
37
- default = '-'
38
- return default if %w[cancelled finished disabled].include?(recurring_logic['state'])
39
-
40
- last_task = recurring_logic['tasks'].max { |a, b| a['start_at'] <=> b['start_at'] }
41
- last_task ? last_task['start_at'] : default
22
+ # The info command hands over a single recurring logic, the list command a
23
+ # whole collection wrapped in `results`. Both are formatted the same way.
24
+ def self.records(data)
25
+ data.is_a?(Hash) && data['results'].is_a?(Array) ? data['results'] : [data]
42
26
  end
43
27
 
44
- def self.format_task_input(task)
45
- return '-' unless task
46
-
47
- task['action']
28
+ # The recurring_logics API already computes the action, the occurrences and
29
+ # the limits (see the `base` rabl view). The extension only normalizes them:
30
+ # the API spells the occurrences with a single "r", so they are copied to
31
+ # the corrected keys and rendered as dates, while blank limits show
32
+ # "Unlimited". The action, occurrences and purpose are nilled when empty so
33
+ # their `hide_blank` fields skip the line entirely in the info output.
34
+ # Working off these fields keeps the list and the info command consistent,
35
+ # as the list output has no `tasks` to recompute them from.
36
+ def self.format_record(data)
37
+ data['action'] = nil if data['action'].to_s.empty?
38
+ data['last_occurrence'] = data['last_occurence']
39
+ data['next_occurrence'] = data['next_occurence']
40
+ data['iteration_limit'] = format_recurring_logic_limit(data['max_iteration'])
41
+ data['repeat_until'] = format_recurring_logic_limit(data['end_time'])
42
+ data['purpose'] = nil if data['purpose'].to_s.empty?
48
43
  end
49
44
 
50
45
  def self.format_recurring_logic_limit(thing)
@@ -2,26 +2,33 @@ module HammerCLIForemanTasks
2
2
  class RecurringLogic < HammerCLIForeman::Command
3
3
  resource :recurring_logics
4
4
 
5
- class ListCommand < HammerCLIForeman::ListCommand
6
- output do
5
+ # The list and the info command show the same set of fields. They share this
6
+ # base definition and both let the RecurringLogic extension format it the same
7
+ # way, so their output stays consistent. It is a method rather than a constant
8
+ # on purpose - autoload_subcommands scans the constants of this class.
9
+ def self.output_fields
10
+ proc do
7
11
  field :id, _('ID')
8
12
  field :cron_line, _('Cron line')
9
13
  field :task_count, _('Task count')
10
- field :action, _('Action')
11
- field :last_occurence, _('Last occurrence'), Fields::Date
12
- field :next_occurence, _('Next occurrence'), Fields::Date
13
14
  field :iteration, _('Iteration')
14
- field :max_iteration, _('Iteration limit')
15
15
  field :end_time, _('End time')
16
16
  field :state, _('State')
17
- field :purpose, _('Purpose')
17
+ field :purpose, _('Purpose'), nil, hide_blank: true
18
18
  end
19
+ end
20
+
21
+ class ListCommand < HammerCLIForeman::ListCommand
22
+ output(&RecurringLogic.output_fields)
19
23
 
20
24
  build_options
25
+
26
+ extend_with(HammerCLIForemanTasks::CommandExtensions::RecurringLogic.new)
21
27
  end
22
28
 
23
29
  class InfoCommand < HammerCLIForeman::InfoCommand
24
- output ListCommand.output_definition
30
+ output(&RecurringLogic.output_fields)
31
+
25
32
  build_options
26
33
 
27
34
  extend_with(HammerCLIForemanTasks::CommandExtensions::RecurringLogic.new)
@@ -53,7 +60,7 @@ module HammerCLIForemanTasks
53
60
  command_name 'delete'
54
61
  desc _("Delete all recuring logics filtered by the arguments")
55
62
  failure_message _('Could not delete recurring logics')
56
- output ListCommand.output_definition
63
+ output(&RecurringLogic.output_fields)
57
64
 
58
65
  def execute
59
66
  response = send_request
@@ -1,5 +1,5 @@
1
1
  module HammerCLIForemanTasks
2
2
  def self.version
3
- @version ||= Gem::Version.new('0.0.25')
3
+ @version ||= Gem::Version.new('0.1.0')
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hammer_cli_foreman_tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.25
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  requirements: []
126
- rubygems_version: 4.0.10
126
+ rubygems_version: 4.0.20
127
127
  specification_version: 4
128
128
  summary: Foreman CLI plugin for showing tasks information for resoruces and users
129
129
  test_files: []