takelage 0.13.2 → 0.13.3

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/bin/tau +1 -0
  4. data/lib/Thorfile +2 -0
  5. data/lib/takelage/bit/check/cli.rb +2 -2
  6. data/lib/takelage/bit/check/module.rb +21 -12
  7. data/lib/takelage/bit/cli.rb +1 -3
  8. data/lib/takelage/bit/clipboard/cli.rb +2 -4
  9. data/lib/takelage/bit/clipboard/module.rb +264 -194
  10. data/lib/takelage/bit/scope/cli.rb +2 -2
  11. data/lib/takelage/bit/scope/module.rb +64 -59
  12. data/lib/takelage/completion/cli.rb +2 -2
  13. data/lib/takelage/docker/check/cli.rb +2 -2
  14. data/lib/takelage/docker/check/module.rb +6 -8
  15. data/lib/takelage/docker/cli.rb +2 -3
  16. data/lib/takelage/docker/container/check/cli.rb +2 -2
  17. data/lib/takelage/docker/container/check/module.rb +28 -19
  18. data/lib/takelage/docker/container/cli.rb +13 -10
  19. data/lib/takelage/docker/container/module.rb +143 -110
  20. data/lib/takelage/docker/image/check/cli.rb +2 -3
  21. data/lib/takelage/docker/image/check/module.rb +26 -12
  22. data/lib/takelage/docker/image/cli.rb +3 -4
  23. data/lib/takelage/docker/image/module.rb +19 -14
  24. data/lib/takelage/docker/image/tag/check/cli.rb +2 -3
  25. data/lib/takelage/docker/image/tag/check/module.rb +33 -17
  26. data/lib/takelage/docker/image/tag/cli.rb +2 -3
  27. data/lib/takelage/docker/image/tag/latest/cli.rb +2 -3
  28. data/lib/takelage/docker/image/tag/latest/module.rb +6 -5
  29. data/lib/takelage/docker/image/tag/list/cli.rb +2 -3
  30. data/lib/takelage/docker/image/tag/list/module.rb +19 -16
  31. data/lib/takelage/docker/socket/cli.rb +2 -3
  32. data/lib/takelage/docker/socket/module.rb +137 -107
  33. data/lib/takelage/git/check/cli.rb +2 -2
  34. data/lib/takelage/git/check/module.rb +53 -35
  35. data/lib/takelage/git/cli.rb +2 -3
  36. data/lib/takelage/info/cli.rb +2 -3
  37. data/lib/takelage/info/project/cli.rb +2 -2
  38. data/lib/takelage/lib/config.rb +62 -45
  39. data/lib/takelage/lib/logging.rb +33 -16
  40. data/lib/takelage/lib/project.rb +43 -28
  41. data/lib/takelage/lib/subcmd.rb +2 -0
  42. data/lib/takelage/lib/system.rb +43 -27
  43. data/lib/takelage/self/cli.rb +2 -0
  44. data/lib/takelage/self/config/cli.rb +2 -0
  45. data/lib/takelage/self/module.rb +2 -0
  46. data/lib/takelage/version +1 -1
  47. data/lib/takelage.rb +6 -7
  48. metadata +1 -1
@@ -1,80 +1,97 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # takelage config module
2
4
  module ConfigModule
3
-
4
5
  # takelage config class.
5
6
  class TakelageConfig
6
-
7
+ include Singleton
7
8
  include LoggingModule
8
9
  include SystemModule
9
10
 
10
11
  attr_accessor :active, :default, :home, :project
11
12
 
12
13
  def initialize
13
- @active = Hash.new
14
- @default = Hash.new
15
- @home = Hash.new
16
- @project = Hash.new
14
+ @active = {}
15
+ @default = {}
16
+ @home = {}
17
+ @project = {}
17
18
  end
18
19
  end
19
20
 
20
- # Global singleton config
21
- @@config = TakelageConfig.new
22
-
23
21
  # Initialze config
24
22
  def initialize_config
25
23
  log.debug "takelage version: #{Takelage::VERSION}"
26
24
  log.debug "Current working directory: #{Dir.pwd}"
27
25
 
28
- # read default config file in lib
29
- default_file = "#{File.dirname(__FILE__)}/../default.yml"
30
- default_file = File.expand_path default_file
31
- if File.exist? default_file
32
- @@config.default = read_yaml_file(default_file) || Hash.new
33
- @@config.default = @@config.default.sort.to_h
34
- end
35
-
36
- # read custom config file in $HOME
37
- home_file = "#{Dir.home}/.takelage.yml"
38
- if File.exist? home_file
39
- @@config.home = read_yaml_file(home_file) || Hash.new
40
- @@config.home = @@config.home.sort.to_h
41
- end
42
-
43
- # read custom config file next to Rakefile
44
- file, path = Rake.application.find_rakefile_location
45
- if path
46
- project_file = "#{path}/takelage.yml"
47
- @@config.project = read_yaml_file(project_file) || Hash.new
48
- @@config.project = @@config.project.sort.to_h
49
- end
50
-
51
- # make a clone or else we'll change the original hash
52
- default = @@config.default.clone
53
- home = @@config.home.clone
54
- project = @@config.project.clone
55
-
56
- # merge default and home and project to active
57
- # project wins against home wins against default
58
- project_over_home = home.merge!(project)
59
-
60
- @@config.active = default.merge!(project_over_home)
61
- @@config.active = @@config.active.sort.to_h
26
+ TakelageConfig.instance.default = _config_read_default
27
+ TakelageConfig.instance.home = _config_read_home
28
+ TakelageConfig.instance.project = _config_read_project
29
+ TakelageConfig.instance.active = _config_merge_active
62
30
  end
63
31
 
64
32
  # @return [Object] global singleton config
65
33
  def config
66
- @@config
34
+ TakelageConfig.instance
67
35
  end
68
36
 
69
37
  # @return [Boolean] check if config keys are configured
70
38
  def configured?(config_keys)
71
39
  @configured = true
72
40
  config_keys.each do |config_key|
73
- unless @@config.active.key? config_key
41
+ unless TakelageConfig.instance.active.key? config_key
74
42
  log.error "Please configure \"#{config_key}\""
75
43
  @configured = false
76
44
  end
77
45
  end
78
46
  @configured
79
47
  end
48
+
49
+ private
50
+
51
+ # Read default config file in lib.
52
+ def _config_read_default
53
+ default_file = File.expand_path("#{File.dirname(__FILE__)}/../default.yml")
54
+
55
+ return {} unless File.exist? default_file
56
+
57
+ default_yaml = read_yaml_file(default_file) || {}
58
+
59
+ default_yaml.sort.to_h
60
+ end
61
+
62
+ # Read custom config file in $HOME.
63
+ def _config_read_home
64
+ home_file = "#{Dir.home}/.takelage.yml"
65
+
66
+ return {} unless File.exist? home_file
67
+
68
+ home_yaml = read_yaml_file(home_file) || {}
69
+
70
+ home_yaml.sort.to_h
71
+ end
72
+
73
+ # Read custom config file next to Rakefile.
74
+ def _config_read_project
75
+ _rakefile, path = Rake.application.find_rakefile_location
76
+ project_file = "#{path}/takelage.yml"
77
+
78
+ return {} unless File.exist? project_file
79
+
80
+ project_yaml = read_yaml_file(project_file) || {}
81
+
82
+ project_yaml.sort.to_h
83
+ end
84
+
85
+ # Merge active config
86
+ def _config_merge_active
87
+ # make a clone or else we'll change the original hash
88
+ default = TakelageConfig.instance.default.clone
89
+ home = TakelageConfig.instance.home.clone
90
+ project = TakelageConfig.instance.project.clone
91
+
92
+ # merge default and home and project to active
93
+ # project wins against home wins against default
94
+ project_over_home = home.merge!(project)
95
+ default.merge!(project_over_home).sort.to_h
96
+ end
80
97
  end
@@ -1,30 +1,47 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # takelage logging module
2
4
  module LoggingModule
5
+ # takelage logger
6
+ class TakelageLogger
7
+ include Singleton
8
+
9
+ attr_accessor :logger
3
10
 
4
- # Global singleton logger
5
- @@log = Logger.new(STDOUT)
11
+ def initialize
12
+ @logger = Logger.new(STDOUT)
13
+ end
14
+ end
6
15
 
7
16
  # Initialize logger with loglevel.
8
17
  def initialize_logging(loglevel)
18
+ TakelageLogger.instance.logger.formatter = _logging_get_log_format
19
+ log_level_in_use = _logging_get_log_level loglevel
20
+ TakelageLogger.instance.logger.level = log_level_in_use
21
+ TakelageLogger.instance.logger.debug "Using loglevel #{log_level_in_use}"
22
+ end
9
23
 
10
- # logger: format
11
- log.formatter = proc do |severity, datetime, progname, msg|
24
+ # @return [Object] global singleton logger
25
+ def log
26
+ TakelageLogger.instance.logger
27
+ end
28
+
29
+ private
30
+
31
+ def _logging_get_log_format
32
+ proc do |severity, _datetime, _progname, msg|
12
33
  "[#{severity}] #{msg}\n"
13
34
  end
35
+ end
14
36
 
15
- # logger: level
16
- if %w(FATAL ERROR WARN INFO DEBUG).include? loglevel
17
- log.level = loglevel
18
- log.debug "Using loglevel #{loglevel}"
37
+ def _logging_get_log_level(loglevel)
38
+ if %w[FATAL ERROR WARN INFO DEBUG].include? loglevel
39
+ loglevel
19
40
  else
20
- log.level = Logger::INFO
21
- log.error 'The parameter "loglevel" must be one of FATAL, ERROR, WARN, INFO, DEBUG'
22
- log.info 'Using loglevel INFO'
41
+ TakelageLogger.instance.logger.error 'The parameter "loglevel"' \
42
+ ' must be one of FATAL, ERROR, WARN, INFO, DEBUG'
43
+ TakelageLogger.instance.logger.info 'Using loglevel INFO'
44
+ Logger::INFO
23
45
  end
24
46
  end
25
-
26
- # @return [Object] global singleton logger
27
- def log
28
- @@log
29
- end
30
47
  end
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # takelage project module
2
4
  module ProjectModule
3
5
  # takelage config class.
4
6
  class TakelageProject
7
+ include Singleton
5
8
  include LoggingModule
6
9
  include SystemModule
7
10
  include ConfigModule
@@ -9,46 +12,58 @@ module ProjectModule
9
12
  attr_accessor :active, :private, :main
10
13
 
11
14
  def initialize
12
- @active = Hash.new
13
- @private = Hash.new
14
- @main = Hash.new
15
+ @active = {}
16
+ @private = {}
17
+ @main = {}
15
18
  end
16
19
  end
17
20
 
18
- # Global singleton config
19
- @@project = TakelageProject.new
20
-
21
21
  # Initialze project
22
22
  def initialize_project
23
- _rakefile, path = Rake.application.find_rakefile_location
23
+ TakelageProject.instance.main = _project_read_main
24
+ TakelageProject.instance.private = _project_read_private
25
+ TakelageProject.instance.active = _project_merge_active
26
+ end
27
+
28
+ # @return [Object] global singleton project
29
+ def project
30
+ TakelageProject.instance
31
+ end
24
32
 
25
- main_file = "#{path}/#{@@project.config.active['info_project_main']}"
26
- private_file = "#{path}/#{@@project.config.active['info_project_private']}"
33
+ private
27
34
 
28
- # read main project info
29
- if File.exist? main_file
30
- @@project.main = read_yaml_file(main_file) || {}
31
- @@project.main = @@project.main.sort.to_h
32
- end
35
+ # Read main YAML file.
36
+ def _project_read_main
37
+ _rakefile, @path = Rake.application.find_rakefile_location
38
+ main_file = "#{@path}/" \
39
+ "#{TakelageProject.instance.config.active['info_project_main']}"
33
40
 
34
- # read private project info
35
- if File.exist? private_file
36
- @@project.private = read_yaml_file(private_file) || {}
37
- @@project.private = @@project.private.sort.to_h
38
- end
41
+ return {} unless File.exist? main_file
42
+
43
+ read_yaml_file(main_file).sort.to_h || {}
44
+ end
45
+
46
+ # Read private YAML file.
47
+ def _project_read_private
48
+ _rakefile, @path = Rake.application.find_rakefile_location
49
+ private_file = "#{@path}/" \
50
+ "#{TakelageProject.instance.config.active['info_project_private']}"
51
+
52
+ return {} unless File.exist? private_file
53
+
54
+ private_yaml = read_yaml_file(private_file) || {}
55
+
56
+ private_yaml.sort.to_h
57
+ end
39
58
 
59
+ # Merge active configuration.
60
+ def _project_merge_active
40
61
  # make a clone or else we'll change the original hash
41
- main = @@project.main.clone
42
- private = @@project.private.clone
62
+ main = TakelageProject.instance.main.clone
63
+ private = TakelageProject.instance.private.clone
43
64
 
44
65
  # merge main and private to active
45
66
  # private wins against main
46
- @@project.active = main.merge!(private)
47
- @@project.active = @@project.active.sort.to_h
48
- end
49
-
50
- # @return [Object] global singleton project
51
- def project
52
- @@project
67
+ main.merge!(private).sort.to_h
53
68
  end
54
69
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Thor with subcommands that work correctly with help
2
4
  class SubCommandBase < Thor
3
5
  # Set the subcommand banner
@@ -1,47 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
  require 'open3'
3
5
  require 'yaml'
4
6
 
5
7
  # Interaction with the operating system
6
8
  module SystemModule
7
- # Print hash as yaml.
9
+ # Convert hash to yaml.
10
+ # @return [String] yaml of hash
8
11
  def hash_to_yaml(hash)
9
12
  return nil.to_yaml if hash == {}
10
13
 
11
14
  hash.to_yaml({ line_width: -1 })
12
15
  end
13
16
 
17
+ # Read yaml file.
14
18
  # @return [Hash] content of yaml file
15
- # rubocop:disable Metrics/MethodLength
16
19
  def read_yaml_file(file)
17
20
  log.debug "Reading YAML file \"#{file}\""
21
+ return nil unless _file_exists? file
22
+ return nil unless _file_read file
23
+ return nil unless _parse_yaml @content_yaml
18
24
 
19
- # Check file existence
20
- unless File.exist? file
21
- log.debug "File \"#{file}\" doesn't exist"
22
- return nil
23
- end
24
-
25
- # Read file
26
- begin
27
- content_yaml = File.read file
28
- rescue SystemCallError
29
- log.debug "Unable to read file \"#{file}\""
30
- return nil
31
- end
32
-
33
- # Parse YAML
34
- begin
35
- content = YAML.safe_load content_yaml
36
- rescue Psych::SyntaxError
37
- log.debug "Invalid YAML file \"#{file}\""
38
- log.debug "Try: yamllint #{file}"
39
- return nil
40
- end
41
-
42
- content
25
+ @content
43
26
  end
44
- # rubocop:enable Metrics/MethodLength
45
27
 
46
28
  # Remove directory tree.
47
29
  def rm_fr(directory)
@@ -85,4 +67,38 @@ module SystemModule
85
67
  log.debug "Command \"#{command}\" has exit status \"#{status.exitstatus}\""
86
68
  status
87
69
  end
70
+
71
+ private
72
+
73
+ # Check if file exists.
74
+ def _file_exists?(file)
75
+ unless File.exist? file
76
+ log.debug "File \"#{file}\" doesn't exist"
77
+ return false
78
+ end
79
+ true
80
+ end
81
+
82
+ # Read yaml file.
83
+ def _file_read(file)
84
+ begin
85
+ @content_yaml = File.read file
86
+ rescue SystemCallError
87
+ log.debug "Unable to read file \"#{file}\""
88
+ return false
89
+ end
90
+ true
91
+ end
92
+
93
+ # Parse yaml file.
94
+ def _parse_yaml(content_yaml)
95
+ begin
96
+ @content = YAML.safe_load content_yaml
97
+ rescue Psych::SyntaxError
98
+ log.debug "Invalid YAML file \"#{file}\""
99
+ log.debug "Try: yamllint #{file}"
100
+ return false
101
+ end
102
+ true
103
+ end
88
104
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Takelage
2
4
  # semantic version number
3
5
  VERSION = (File.read "#{File.dirname(__FILE__)}/../version").chomp
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Takelage
2
4
  # takelage bit
3
5
  class SelfConfig < SubCommandBase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # takelage self
2
4
  module SelfModule
3
5
  # Backend method for config self.
data/lib/takelage/version CHANGED
@@ -1 +1 @@
1
- 0.13.2
1
+ 0.13.3
data/lib/takelage.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'docker_registry2'
2
4
  require 'etc'
3
5
  require 'fileutils'
@@ -5,6 +7,7 @@ require 'fylla'
5
7
  require 'json'
6
8
  require 'logger'
7
9
  require 'rake'
10
+ require 'singleton'
8
11
  require 'socket'
9
12
  require 'thor'
10
13
  require 'timeout'
@@ -54,13 +57,10 @@ require_relative 'takelage/self/config/cli'
54
57
  require_relative 'takelage/self/module'
55
58
  require_relative 'takelage/self/cli'
56
59
 
57
-
58
60
  # Facilitate the takelage devops workflow.
59
61
  module Takelage
60
-
61
62
  # takelage
62
63
  class CLI < Thor
63
-
64
64
  include LoggingModule
65
65
  include SystemModule
66
66
  include ConfigModule
@@ -72,12 +72,11 @@ module Takelage
72
72
  attr_reader :bash_fylla
73
73
 
74
74
  option :loglevel,
75
- :aliases => 'l',
76
- :default => 'INFO',
77
- :desc => 'One of: FATAL, ERROR, WARN, INFO, DEBUG'
75
+ aliases: 'l',
76
+ default: 'INFO',
77
+ desc: 'One of: FATAL, ERROR, WARN, INFO, DEBUG'
78
78
  # Initialize takelage cli.
79
79
  def initialize(args = [], local_options = {}, configuration = {})
80
-
81
80
  # Initialize thor parent class
82
81
  super args, local_options, configuration
83
82
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: takelage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.2
4
+ version: 0.13.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geospin