cmt 0.0.1 → 0.0.3

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
  SHA256:
3
- metadata.gz: f22c54538014ff0c05f465f326f35db0237f25498df57aebdc36d3ebf574fbef
4
- data.tar.gz: b26bf08d47349d909f22565a2fdcefb5c3194e32ff89c62d0114b1e5bb77ee0d
3
+ metadata.gz: 21823d54ba6bdc91c53704bf6361b4f07fd996169fcd5b7ae1a89c9c04781858
4
+ data.tar.gz: d3ca7edc2bf754d6493e074c7ff52b53980248357528dfdf9bb2f7577620baa7
5
5
  SHA512:
6
- metadata.gz: 4c89b40790bffff57a425db4219f28022893baa814223a7a8cd480b1e0edfa92abfae41dc8e280154fa1c372dcbe39243128bb125055c092ba96959f63ccdcc0
7
- data.tar.gz: 4f157269c19116c1fd02962745e0e4ff458d762520840a67049686cbab995463ebc8915faa3c8b728c414dcf0ffddbc49d5f558213a4df7f50ec1d32472f74b8
6
+ metadata.gz: aa051e339275cc4dd607b3d1eaa16e45e502133c23e22dd8a881aedfd00e8c33d6e006b3784cf4cba9e2d8ea574a25b34313fe2a6476891f0b8858c5b5d4dd0d
7
+ data.tar.gz: 97eebdb9f5708aea8bbb24c505fab72b8a5318f527c5177a25a450775131bb1481208862d73087b070ee227c078efb97a2d52ccb64b9787b2cf232f40034cd77
data/bin/cmt CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require_relative '../lib/cmt.rb'
3
+ require_relative '../lib/cmt'
data/lib/cmt.rb CHANGED
@@ -1,29 +1,34 @@
1
1
  require "thor"
2
- require 'pathname'
3
- require 'fileutils'
4
- require 'json'
2
+ require "pathname"
3
+ require "fileutils"
4
+ require "json"
5
5
  require "logger"
6
6
 
7
- require_relative './config/git_config'
8
- require_relative './dotfiles/dotfiles_cli'
9
- require_relative './pkg/pkg'
7
+ require_relative "config/git_config"
8
+ require_relative "dotfiles/dotfiles_cli"
9
+ require_relative "pkg/pkg"
10
+ require_relative "version"
10
11
 
11
- $logger = Logger.new(STDOUT)
12
- $logger.formatter = proc do |severity, datetime, progname, msg|
13
- date_format = datetime.strftime("%Y-%m-%d %H:%M:%S")
14
- JSON.dump(date: "#{date_format}", severity:"#{severity.ljust(5)}", pid:"##{Process.pid}", message: msg) + "\n"
12
+ $logger = Logger.new($stdout)
13
+ $logger.formatter = proc do |severity, datetime, _progname, msg|
14
+ date_format = datetime.strftime("%Y-%m-%d %H:%M:%S")
15
+ JSON.dump(date: date_format, severity: severity.ljust(5), pid: "##{Process.pid}", message: msg) + "\n" # rubocop:disable Style/StringConcatenation
15
16
  end
16
17
 
17
18
  class Cmt < Thor
18
- desc "config SUBCOMMAND ...ARGS", "manage set of tracked repositories"
19
- subcommand "config", GitConfig
19
+ desc "config SUBCOMMAND ...ARGS", "manage set of tracked repositories"
20
+ subcommand "config", GitConfig
20
21
 
21
- desc "dotfiles SUBCOMMAND ...ARGS", "manage set of tracked repositories"
22
- subcommand "dotfiles", DotfilesCli
22
+ desc "dotfiles SUBCOMMAND ...ARGS", "manage set of tracked repositories"
23
+ subcommand "dotfiles", DotfilesCli
23
24
 
24
- desc "pkg SUBCOMMAND ...ARGS", "manage set of tracked repositories"
25
- subcommand "pkg", Pkg
25
+ desc "pkg SUBCOMMAND ...ARGS", "manage set of tracked repositories"
26
+ subcommand "pkg", Pkg
27
+
28
+ desc "version", "Print version"
29
+ def version
30
+ puts(VERSION)
31
+ end
26
32
  end
27
33
 
28
34
  Cmt.start(ARGV)
29
-
data/lib/config/config.rb CHANGED
@@ -1,20 +1,18 @@
1
1
  require "thor"
2
- require 'fileutils'
2
+ require "fileutils"
3
3
 
4
- $CONFIG_DIR = File.join(Dir.home, '.config', 'cmt')
4
+ $CONFIG_DIR = File.join(Dir.home, ".config", "cmt")
5
5
 
6
6
  class Config
7
- def self.get_config_json(file, default_config)
8
- FileUtils.mkdir_p File.dirname(file)
9
- if !File.exists?(file)
10
- File.open(file, 'w') {|f| JSON.dump(default_config, f)}
11
- end
7
+ def self.get_config_json(file, default_config)
8
+ FileUtils.mkdir_p File.dirname(file)
9
+ File.write(file, JSON.pretty_generate(default_config, { indent: " " })) unless File.exist?(file)
12
10
 
13
- config = JSON.load_file(file)
14
- return default_config.merge(config)
15
- end
11
+ config = JSON.load_file(file)
12
+ default_config.merge(config)
13
+ end
16
14
 
17
- def self.write_config_file(file, config)
18
- File.open(file, 'w') {|f| f.write(JSON.pretty_generate(config, {indent: ' '}))}
19
- end
15
+ def self.write_config_file(file, config)
16
+ File.write(file, JSON.pretty_generate(config, { indent: " " }))
17
+ end
20
18
  end
@@ -1,63 +1,71 @@
1
1
  require "thor"
2
2
 
3
- require_relative './config'
3
+ require_relative "config"
4
4
 
5
5
  class GitConfig < Thor
6
- desc "init", "Init"
7
- option :force, :type => :boolean, :default => false
8
- def init(repo)
9
- force = options['force']
10
-
11
- if File.exists? $CONFIG_DIR
12
- if force
13
- FileUtils.rm_rf($CONFIG_DIR)
14
- else
15
- $logger.error("Config already exists at '#{$CONFIG_DIR}'")
16
- abort("Config already exists at '#{$CONFIG_DIR}'")
17
- end
18
- end
19
-
20
- `git clone #{repo} #{$CONFIG_DIR}`
6
+ desc "init", "Init"
7
+ option :force, type: :boolean, default: false
8
+ def init(repo)
9
+ force = options["force"]
10
+
11
+ if File.exist? $CONFIG_DIR
12
+ if force
13
+ FileUtils.rm_rf($CONFIG_DIR)
14
+ else
15
+ $logger.error("Config already exists at '#{$CONFIG_DIR}'")
16
+ abort("Config already exists at '#{$CONFIG_DIR}'")
17
+ end
18
+ end
19
+
20
+ `git clone #{repo} #{$CONFIG_DIR}`
21
+ end
22
+
23
+ desc "update", "update"
24
+ option :message, default: "Update config"
25
+ def update
26
+ message = options['message']
27
+ Dir.chdir($CONFIG_DIR) do
28
+ changes = `git status --porcelain=v1`
29
+ num_changes = changes.split.length
30
+
31
+ if num_changes.zero?
32
+ $logger.error("No changes to commit in '#{$CONFIG_DIR}'")
33
+ abort("No changes to commit in '#{$CONFIG_DIR}'")
34
+ else
35
+ $logger.info("Commit changes")
36
+ system 'git', 'add', '.'
37
+ system 'git', 'commit', '-m', "'#{message}'"
38
+ system 'git', 'push'
39
+ end
21
40
  end
41
+ end
22
42
 
23
- desc "update", "update"
24
- option :message, :default => "Update config"
25
- def update()
26
- message = options['message']
27
- Dir.chdir($CONFIG_DIR) do
28
- changes = `git status --porcelain=v1`
29
- num_changes = changes.split(' ').length()
30
-
31
- if num_changes == 0
32
- $logger.error("No changes to commit in '#{$CONFIG_DIR}'")
33
- abort("No changes to commit in '#{$CONFIG_DIR}'")
34
- else
35
- $logger.info("Commit changes")
36
- system 'git', 'add', '.'
37
- system 'git', 'commit', '-m', "'#{message}'"
38
- system 'git', 'push'
39
- end
40
- end
43
+ desc "status", "Show git status in '#{$CONFIG_DIR}'"
44
+ def status(*args)
45
+ Dir.chdir($CONFIG_DIR) do
46
+ system 'git', 'status', *args
41
47
  end
48
+ end
42
49
 
43
- desc "status", "Show git status in '#{$CONFIG_DIR}'"
44
- def status(*args)
45
- Dir.chdir($CONFIG_DIR) do
46
- system 'git', 'status', *args
47
- end
50
+ desc "pull", "Pull newest changes in '#{$CONFIG_DIR}'"
51
+ def pull(*args)
52
+ Dir.chdir($CONFIG_DIR) do
53
+ system 'git', 'pull', *args
48
54
  end
55
+ end
49
56
 
50
- desc "pull", "Pull newest changes in '#{$CONFIG_DIR}'"
51
- def status(*args)
52
- Dir.chdir($CONFIG_DIR) do
53
- system 'git', 'pull', *args
54
- end
57
+ desc "exec", "Execute any git command in '#{$CONFIG_DIR}'"
58
+ def exec(*args)
59
+ Dir.chdir($CONFIG_DIR) do
60
+ system 'git', *args
55
61
  end
62
+ end
56
63
 
57
- desc "exec", "Execute any git command in '#{$CONFIG_DIR}'"
58
- def exec(*args)
59
- Dir.chdir($CONFIG_DIR) do
60
- system 'git', *args
61
- end
64
+ desc "code", "Open '#{$CONFIG_DIR}' in code"
65
+ def code(*args)
66
+ $logger.info("Open '#{$CONFIG_DIR}' in code")
67
+ Dir.chdir($CONFIG_DIR) do
68
+ system 'code', '.', *args
62
69
  end
63
- end
70
+ end
71
+ end
@@ -8,135 +8,130 @@ require_relative '../config/config'
8
8
  require_relative '../util/file_util'
9
9
 
10
10
  class Dotfiles
11
- CONFIG_SUB_DIR = 'dotfiles'
12
- ROOT_PATH = File.join($CONFIG_DIR, CONFIG_SUB_DIR)
13
- CONFIG_FILE = File.join(ROOT_PATH, 'dotfiles.json')
14
- FILES_PATH = File.join(ROOT_PATH, 'files')
15
- FOLDERS_PATH = File.join(ROOT_PATH, 'folders')
11
+ CONFIG_SUB_DIR = 'dotfiles'.freeze
12
+ ROOT_PATH = File.join($CONFIG_DIR, CONFIG_SUB_DIR).freeze
13
+ CONFIG_FILE = File.join(ROOT_PATH, 'dotfiles.json').freeze
14
+ FILES_PATH = File.join(ROOT_PATH, 'files').freeze
15
+ FOLDERS_PATH = File.join(ROOT_PATH, 'folders').freeze
16
16
 
17
- DEFAULT_CONFIG = {
18
- "files" => [],
19
- "folders" => [],
20
- }
17
+ DEFAULT_CONFIG = {
18
+ "files" => [],
19
+ "folders" => []
20
+ }.freeze
21
21
 
22
- def add(file)
22
+ def add(file)
23
+ abs_file = File.absolute_path(file.dup)
23
24
 
24
- abs_file = File.absolute_path(file.dup)
25
+ config = Config.get_config_json(CONFIG_FILE, DEFAULT_CONFIG)
26
+ list = get_sync_list(config, abs_file)
25
27
 
26
- config = Config.get_config_json(CONFIG_FILE, DEFAULT_CONFIG)
27
- list = get_sync_list(config, abs_file)
28
-
29
- parsed_file = FileUtil.to_local_file(abs_file)
28
+ parsed_file = FileUtil.to_local_file(abs_file)
30
29
 
31
- local_path = get_local_path(file)
30
+ local_path = get_local_path(file)
32
31
 
33
- if !list.include? parsed_file
34
- dir = File.dirname(parsed_file)
32
+ unless list.include? parsed_file
33
+ dir = File.dirname(parsed_file)
35
34
 
36
- puts File.join(local_path, dir)
37
-
38
- FileUtils.mkdir_p File.join(local_path, dir)
35
+ puts File.join(local_path, dir)
39
36
 
40
- if File.file?(abs_file)
41
- FileUtils.cp(abs_file, File.join(local_path, parsed_file))
42
- else
43
- FileUtils.cp_r(abs_file, File.join(local_path, parsed_file))
44
- end
45
-
46
- if File.exists? File.join(local_path, parsed_file)
47
- list.append(parsed_file)
48
- end
49
- end
37
+ FileUtils.mkdir_p File.join(local_path, dir)
50
38
 
51
- Config.write_config_file(CONFIG_FILE, config)
39
+ if File.file?(abs_file)
40
+ FileUtils.cp(abs_file, File.join(local_path, parsed_file))
41
+ else
42
+ FileUtils.cp_r(abs_file, File.join(local_path, parsed_file))
43
+ end
52
44
 
53
- $logger.info("Added '#{parsed_file}'")
45
+ list.append(parsed_file) if File.exist? File.join(local_path, parsed_file)
54
46
  end
55
47
 
56
- def remove(file)
57
- local_file = FileUtil.to_local_file(file)
58
- local_file_abs = File.join(get_local_path(file), local_file)
48
+ Config.write_config_file(CONFIG_FILE, config)
59
49
 
60
- config = Config.get_config_json(CONFIG_FILE, DEFAULT_CONFIG)
61
- list = get_sync_list(config, local_file_abs)
50
+ $logger.info("Added '#{parsed_file}'")
51
+ end
62
52
 
53
+ def remove(file)
54
+ local_file = FileUtil.to_local_file(file)
55
+ local_file_abs = File.join(get_local_path(file), local_file)
63
56
 
64
- if list.include? local_file
65
- puts(local_file_abs)
66
- FileUtils.rm_rf(local_file_abs)
67
-
68
- list.delete(local_file)
69
- end
70
-
71
- Config.write_config_file(CONFIG_FILE, config)
57
+ config = Config.get_config_json(CONFIG_FILE, DEFAULT_CONFIG)
58
+ list = get_sync_list(config, local_file_abs)
72
59
 
60
+ if list.include? local_file
61
+ puts(local_file_abs)
62
+ FileUtils.rm_rf(local_file_abs)
73
63
 
74
- $logger.info("Removed '#{local_file}'")
64
+ list.delete(local_file)
75
65
  end
76
66
 
77
- def apply()
78
- $logger.info('Start apply')
67
+ Config.write_config_file(CONFIG_FILE, config)
79
68
 
80
- config = Config.get_config_json(CONFIG_FILE, DEFAULT_CONFIG)
81
- files = config['files']
69
+ $logger.info("Removed '#{local_file}'")
70
+ end
82
71
 
83
- files.each { |file|
84
- dest_file = FileUtil.to_system_file(file)
72
+ def apply
73
+ $logger.info('Start apply')
85
74
 
86
- abs_file = File.join(FILES_PATH, file)
87
- $logger.debug("Copy #{abs_file} to #{dest_file}")
75
+ config = Config.get_config_json(CONFIG_FILE, DEFAULT_CONFIG)
76
+ files = config['files']
88
77
 
89
- FileUtils.cp_r(abs_file, dest_file, remove_destination: true)
90
- }
78
+ files.each do |file|
79
+ dest_file = FileUtil.to_system_file(file)
91
80
 
92
- folders = config['folders']
81
+ abs_file = File.join(FILES_PATH, file)
82
+ $logger.debug("Copy #{abs_file} to #{dest_file}")
93
83
 
94
- folders.each { |folder|
95
- dest_file = File.dirname(FileUtil.to_system_file(folder))
84
+ FileUtils.cp_r(abs_file, dest_file, remove_destination: true)
85
+ end
86
+
87
+ folders = config['folders']
96
88
 
97
- abs_file = File.join(FOLDERS_PATH, folder)
98
- $logger.debug("Copy #{abs_file} to #{dest_file}")
89
+ folders.each do |folder|
90
+ dest_file = File.dirname(FileUtil.to_system_file(folder))
99
91
 
100
- FileUtils.cp_r(abs_file, dest_file, remove_destination: true)
101
- }
92
+ abs_file = File.join(FOLDERS_PATH, folder)
93
+ $logger.debug("Copy #{abs_file} to #{dest_file}")
102
94
 
103
- $logger.info('Finished apply')
95
+ FileUtils.cp_r(abs_file, dest_file, remove_destination: true)
104
96
  end
105
97
 
106
- def sync()
107
- $logger.info('Start sync')
98
+ $logger.info('Finished apply')
99
+ end
108
100
 
109
- config = Config.get_config_json(CONFIG_FILE, DEFAULT_CONFIG)
110
- files = config['files']
101
+ def sync
102
+ $logger.info('Start sync')
111
103
 
112
- files.each { |file|
113
- dest_file = FileUtil.to_system_file(file)
104
+ config = Config.get_config_json(CONFIG_FILE, DEFAULT_CONFIG)
105
+ files = config['files']
114
106
 
115
- abs_file = File.join(FILES_PATH, file)
116
- $logger.debug("Copy #{dest_file} to #{abs_file}")
107
+ files.each do |file|
108
+ dest_file = FileUtil.to_system_file(file)
117
109
 
118
- FileUtils.cp_r(dest_file, abs_file, remove_destination: true)
119
- }
110
+ abs_file = File.join(FILES_PATH, file)
111
+ $logger.debug("Copy #{dest_file} to #{abs_file}")
120
112
 
121
- folders = config['folders']
113
+ FileUtils.cp_r(dest_file, abs_file, remove_destination: true)
114
+ end
122
115
 
123
- folders.each { |folder|
124
- dest_file = FileUtil.to_system_file(folder)
116
+ folders = config['folders']
125
117
 
126
- abs_file = File.dirname(File.join(FOLDERS_PATH, folder))
127
- $logger.debug("Copy #{dest_file} to #{abs_file}")
118
+ folders.each do |folder|
119
+ dest_file = FileUtil.to_system_file(folder)
128
120
 
129
- FileUtils.cp_r(dest_file, abs_file, remove_destination: true)
130
- }
121
+ abs_file = File.dirname(File.join(FOLDERS_PATH, folder))
122
+ $logger.debug("Copy #{dest_file} to #{abs_file}")
131
123
 
132
- $logger.info('Finished sync')
124
+ FileUtils.cp_r(dest_file, abs_file, remove_destination: true)
133
125
  end
134
126
 
135
- def get_local_path(file)
136
- return File.file?(file) ? FILES_PATH : FOLDERS_PATH
137
- end
127
+ $logger.info('Finished sync')
128
+ end
138
129
 
139
- def get_sync_list(config, file)
140
- return File.file?(file) ? config['files'] : config['folders']
141
- end
130
+ def get_local_path(file)
131
+ return File.file?(file) ? FILES_PATH : FOLDERS_PATH
132
+ end
133
+
134
+ def get_sync_list(config, file)
135
+ return File.file?(file) ? config['files'] : config['folders']
136
+ end
142
137
  end
@@ -1,30 +1,30 @@
1
- require_relative './dotfiles'
1
+ require_relative "dotfiles"
2
2
 
3
3
  class DotfilesCli < Thor
4
- DOTFILES = Dotfiles.new
4
+ DOTFILES = Dotfiles.new
5
5
 
6
- desc "init", "Download objects and refs from another repository"
7
- def init()
8
- DOTFILES.init()
9
- end
6
+ desc "init", "Download objects and refs from another repository"
7
+ def init
8
+ DOTFILES.init
9
+ end
10
10
 
11
- desc "add <file>", "Download objects and refs from another repository"
12
- def add(file)
13
- DOTFILES.add(file)
14
- end
11
+ desc "add <file>", "Download objects and refs from another repository"
12
+ def add(file)
13
+ DOTFILES.add(file)
14
+ end
15
15
 
16
- desc "remove <file>", "Download objects and refs from another repository"
17
- def remove(file)
18
- DOTFILES.remove(file)
19
- end
16
+ desc "remove <file>", "Download objects and refs from another repository"
17
+ def remove(file)
18
+ DOTFILES.remove(file)
19
+ end
20
20
 
21
- desc "apply", "Copies all dotfiles defined in the user config to the system"
22
- def apply()
23
- DOTFILES.apply()
24
- end
21
+ desc "apply", "Copies all dotfiles defined in the user config to the system"
22
+ def apply
23
+ DOTFILES.apply
24
+ end
25
25
 
26
- desc "sync", "Updates all files defined in the user config from the system to the config dir"
27
- def sync()
28
- DOTFILES.sync()
29
- end
26
+ desc "sync", "Updates all files defined in the user config from the system to the config dir"
27
+ def sync
28
+ DOTFILES.sync
29
+ end
30
30
  end
data/lib/pkg/pkg.rb CHANGED
@@ -1,105 +1,104 @@
1
- require 'thor'
1
+ require "thor"
2
2
 
3
- require_relative './pkgm/pacman'
4
- require_relative './pkgm/yay'
5
- require_relative './pkgm/pip'
6
- require_relative './pkgm/snap'
7
- require_relative './pkgm/winget'
8
- require_relative './pkg_config'
3
+ require_relative "pkgm/dnf"
4
+ require_relative "pkgm/pacman"
5
+ require_relative "pkgm/yay"
6
+ require_relative "pkgm/pip"
7
+ require_relative "pkgm/snap"
8
+ require_relative "pkgm/winget"
9
+ require_relative "pkg_config"
9
10
 
10
11
  class Pkg < Thor
11
- SYSTEM_PACKAGE_MANGER = {
12
- 'manjaro' => Pacman,
13
- 'windows' => Winget
14
- }
15
- OTHER_PACKAGE_MANGER = {
16
- 'pip' => Pip,
17
- 'snap' => Snap,
18
- 'yay' => Yay
19
- }
20
- RELEASE_FILE = '/etc/os-release'
12
+ SYSTEM_PACKAGE_MANGER = {
13
+ "manjaro" => Pacman,
14
+ "fedora" => Dnf,
15
+ "windows" => Winget
16
+ }.freeze
17
+ OTHER_PACKAGE_MANGER = {
18
+ "pip" => Pip,
19
+ "snap" => Snap,
20
+ "yay" => Yay
21
+ }.freeze
22
+ RELEASE_FILE = "/etc/os-release".freeze
21
23
 
24
+ desc "install_all", "Install"
25
+ option "pkgm", default: "system"
26
+ def install_all(*args)
27
+ manager = get_package_manager(options["pkgm"])
22
28
 
23
- desc 'install_all', 'Install'
24
- option 'pkgm', default: 'system'
25
- def install_all(*args)
26
- manager = get_package_manager(options['pkgm'])
29
+ config_file = PkgConfig.get_config_file(manager)
30
+ config = Config.get_config_json(config_file, PkgConfig.default_config)
27
31
 
28
- config_file = PkgConfig.get_config_file(manager)
29
- config = Config.get_config_json(config_file, PkgConfig.get_default_config())
32
+ packages = config["packages"]
30
33
 
31
- packages = config['packages']
34
+ manager.install_all(packages, *args)
35
+ end
32
36
 
33
- installed = manager.install_all(packages, *args)
34
- end
37
+ desc "install", "Install"
38
+ option "pkgm", default: "system"
39
+ def install(package, *args)
40
+ manager = get_package_manager(options["pkgm"])
35
41
 
36
- desc 'install', 'Install'
37
- option 'pkgm', default: 'system'
38
- def install(package, *args)
39
- manager = get_package_manager(options['pkgm'])
42
+ installed = manager.install(package, *args)
40
43
 
41
- installed = manager.install(package, *args)
44
+ return unless installed
42
45
 
43
- if installed
44
- PkgConfig.add(manager, package)
45
- end
46
- end
46
+ PkgConfig.add(manager, package)
47
+ end
47
48
 
48
- desc 'update', 'update'
49
- option 'pkgm', default: 'system'
50
- def update(*args)
51
- manager = get_package_manager(options['pkgm'])
49
+ desc "update", "update"
50
+ option "pkgm", default: "system"
51
+ def update(*args)
52
+ manager = get_package_manager(options["pkgm"])
52
53
 
53
- installed = manager.update(*args)
54
- end
54
+ manager.update(*args)
55
+ end
55
56
 
57
+ desc "uninstall", "uninstall"
58
+ option "pkgm", default: "system"
59
+ def uninstall(package, *args)
60
+ manager = get_package_manager(options["pkgm"])
56
61
 
57
- desc 'uninstall', 'uninstall'
58
- option 'pkgm', default: 'system'
59
- def uninstall(package, *args)
60
- manager = get_package_manager(options['pkgm'])
62
+ uninstalled = manager.uninstall(package, *args)
61
63
 
62
- uninstalled = manager.uninstall(package, *args)
64
+ return unless uninstalled
63
65
 
64
- if uninstalled
65
- PkgConfig.remove(manager, package)
66
- end
67
- end
66
+ PkgConfig.remove(manager, package)
67
+ end
68
68
 
69
- no_commands do
70
- def get_package_manager(pkgm)
71
- manager = nil
69
+ no_commands do
70
+ def get_package_manager(pkgm)
71
+ manager = nil
72
72
 
73
- if pkgm == 'system'
73
+ if pkgm == "system"
74
74
 
75
- if Gem.win_platform?
76
- manager = SYSTEM_PACKAGE_MANGER['windows']
77
- else
78
- r = { 'distro' => nil}
79
- if !File.exists?(RELEASE_FILE)
80
- $logger.error("'#{RELEASE_FILE}' does not exist")
81
- abort("'#{RELEASE_FILE}' does not exist")
82
- end
75
+ if Gem.win_platform?
76
+ manager = SYSTEM_PACKAGE_MANGER["windows"]
77
+ else
78
+ r = { "distro" => nil }
79
+ unless File.exist?(RELEASE_FILE)
80
+ $logger.error("'#{RELEASE_FILE}' does not exist")
81
+ abort("'#{RELEASE_FILE}' does not exist")
82
+ end
83
83
 
84
- File.open(RELEASE_FILE, 'r').read.each_line do |line|
85
- r = { 'distro' => $1 } if line =~ /^ID=(.*)/
86
- end
84
+ File.foreach(RELEASE_FILE) do |line|
85
+ r = { "distro" => ::Regexp.last_match(1) } if line =~ /^ID=(.*)/
86
+ end
87
87
 
88
- manager = SYSTEM_PACKAGE_MANGER[r['distro']]
89
- end
90
- else
91
- manager = OTHER_PACKAGE_MANGER[pkgm]
92
- end
88
+ manager = SYSTEM_PACKAGE_MANGER[r["distro"]]
89
+ end
90
+ else
91
+ manager = OTHER_PACKAGE_MANGER[pkgm]
92
+ end
93
93
 
94
- if manager == nil
95
- $logger.error("'#{pkgm}' is not supported")
96
- abort("'#{pkgm}' is not supported")
97
- end
94
+ if manager.nil?
95
+ $logger.error("'#{pkgm}' is not supported")
96
+ abort("'#{pkgm}' is not supported")
97
+ end
98
98
 
99
- $logger.info("Using package manager '#{manager}'")
99
+ $logger.info("Using package manager '#{manager}'")
100
100
 
101
- return manager
102
- end
101
+ manager
103
102
  end
104
-
105
- end
103
+ end
104
+ end
@@ -1,49 +1,45 @@
1
- require 'json'
1
+ require "json"
2
2
 
3
- require_relative '../config/config'
3
+ require_relative "../config/config"
4
4
 
5
5
  class PkgConfig
6
- CONFIG_SUB_DIR = 'pkg'
7
- ROOT_PATH = File.join($CONFIG_DIR, CONFIG_SUB_DIR)
8
- DEFAULT_CONFIG = {
9
- 'repos' => [],
10
- 'packages' => []
11
- }
6
+ CONFIG_SUB_DIR = "pkg".freeze
7
+ ROOT_PATH = File.join($CONFIG_DIR, CONFIG_SUB_DIR).freeze
8
+ DEFAULT_CONFIG = {
9
+ "repos" => [],
10
+ "packages" => []
11
+ }.freeze
12
12
 
13
- def self.add(pkgm, package)
14
- config_file = PkgConfig.get_config_file(pkgm)
13
+ def self.add(pkgm, package)
14
+ config_file = PkgConfig.get_config_file(pkgm)
15
15
 
16
- config = Config.get_config_json(config_file, DEFAULT_CONFIG)
16
+ config = Config.get_config_json(config_file, DEFAULT_CONFIG)
17
17
 
18
- packages = config['packages']
18
+ packages = config["packages"]
19
19
 
20
- if !packages.include? package
21
- packages.append package
22
- end
20
+ packages.append package unless packages.include? package
23
21
 
24
- Config.write_config_file(config_file, config)
25
- end
22
+ Config.write_config_file(config_file, config)
23
+ end
26
24
 
27
- def self.remove(pkgm, package)
28
- config_file = PkgConfig.get_config_file(pkgm)
25
+ def self.remove(pkgm, package)
26
+ config_file = PkgConfig.get_config_file(pkgm)
29
27
 
30
- config = Config.get_config_json(config_file, DEFAULT_CONFIG)
28
+ config = Config.get_config_json(config_file, DEFAULT_CONFIG)
31
29
 
32
- packages = config['packages']
30
+ packages = config["packages"]
33
31
 
34
- if packages.include? package
35
- packages.delete package
36
- end
32
+ packages.delete package if packages.include? package
37
33
 
38
- Config.write_config_file(config_file, config)
39
- end
34
+ Config.write_config_file(config_file, config)
35
+ end
40
36
 
41
- def self.get_config_file(pkgm)
42
- pkgm = "#{pkgm}".downcase
43
- return File.join(ROOT_PATH, "#{pkgm}.json")
44
- end
37
+ def self.get_config_file(pkgm)
38
+ pkgm = pkgm.downcase
39
+ File.join(ROOT_PATH, "#{pkgm}.json")
40
+ end
45
41
 
46
- def self.get_default_config()
47
- return DEFAULT_CONFIG
48
- end
49
- end
42
+ def self.default_config
43
+ DEFAULT_CONFIG
44
+ end
45
+ end
@@ -0,0 +1,17 @@
1
+ class Dnf
2
+ def self.install_all(packages, *args)
3
+ system "sudo", "dnf", "install", *args, *packages
4
+ end
5
+
6
+ def self.install(package, *args)
7
+ system "sudo", "dnf", "install", *args, package
8
+ end
9
+
10
+ def self.update(*args)
11
+ system "sudo", "dnf", "update", *args
12
+ end
13
+
14
+ def self.uninstall(package, *args)
15
+ system "sudo", "dnf", "remove", *args, package
16
+ end
17
+ end
@@ -1,18 +1,17 @@
1
-
2
1
  class Pacman
3
- def self.install_all(packages, *args)
4
- return system 'sudo', 'pacman', '-Sy', *args, *packages
5
- end
2
+ def self.install_all(packages, *args)
3
+ system "sudo", "pacman", "-Sy", *args, *packages
4
+ end
6
5
 
7
- def self.install(package, *args)
8
- return system 'sudo', 'pacman', '-Sy', *args, package
9
- end
6
+ def self.install(package, *args)
7
+ system "sudo", "pacman", "-Sy", *args, package
8
+ end
10
9
 
11
- def self.update(*args)
12
- return system 'sudo', 'pacman', '-Syu', *args
13
- end
10
+ def self.update(*args)
11
+ system "sudo", "pacman", "-Syu", *args
12
+ end
14
13
 
15
- def self.uninstall(package, *args)
16
- return system 'sudo', 'pacman', '-R', *args, package
17
- end
18
- end
14
+ def self.uninstall(package, *args)
15
+ system "sudo", "pacman", "-R", *args, package
16
+ end
17
+ end
data/lib/pkg/pkgm/pip.rb CHANGED
@@ -1,19 +1,18 @@
1
-
2
1
  class Pip
3
- def self.install_all(packages, *args)
4
- return system 'python3', '-m', 'pip', 'install', *args, *packages
5
- end
2
+ def self.install_all(packages, *args)
3
+ system "python3", "-m", "pip", "install", *args, *packages
4
+ end
6
5
 
7
- def self.install(package, *args)
8
- return system 'python3', '-m', 'pip', 'install', *args, package
9
- end
6
+ def self.install(package, *args)
7
+ system "python3", "-m", "pip", "install", *args, package
8
+ end
10
9
 
11
- def self.update(*args)
12
- $logger.error("Update is not supported for pip")
13
- abort("Update is not supported for pip")
14
- end
10
+ def self.update(*_args)
11
+ $logger.error("Update is not supported for pip")
12
+ abort("Update is not supported for pip")
13
+ end
15
14
 
16
- def self.uninstall(package, *args)
17
- return system 'python3', '-m', 'pip', 'uninstall', *args, package
18
- end
19
- end
15
+ def self.uninstall(package, *args)
16
+ system "python3", "-m", "pip", "uninstall", *args, package
17
+ end
18
+ end
data/lib/pkg/pkgm/snap.rb CHANGED
@@ -1,19 +1,18 @@
1
-
2
1
  class Snap
3
- def self.install_all(packages, *args)
4
- return system 'snap', 'install', *args, *packages
5
- end
2
+ def self.install_all(packages, *args)
3
+ system "snap", "install", *args, *packages
4
+ end
6
5
 
7
- def self.install(package, *args)
8
- return system 'snap', 'install', *args, package
9
- end
6
+ def self.install(package, *args)
7
+ system "snap", "install", *args, package
8
+ end
10
9
 
11
- def self.update(*args)
12
- $logger.error("Update is not supported for snap")
13
- abort("Update is not supported for snap")
14
- end
10
+ def self.update(*_args)
11
+ $logger.error("Update is not supported for snap")
12
+ abort("Update is not supported for snap")
13
+ end
15
14
 
16
- def self.uninstall(package, *args)
17
- return system 'snap', 'remove', *args, package
18
- end
19
- end
15
+ def self.uninstall(package, *args)
16
+ system "snap", "remove", *args, package
17
+ end
18
+ end
@@ -1,21 +1,19 @@
1
-
2
1
  class Winget
3
- def self.install_all(packages, *args)
4
- packages.each { |package|
5
- Winget.install(package, *args)
6
- }
2
+ def self.install_all(packages, *args)
3
+ packages.each do |package|
4
+ Winget.install(package, *args)
7
5
  end
6
+ end
8
7
 
9
- def self.install(package, *args)
10
- return system 'winget', 'install', *args, "--id=#{package}", "-e"
11
- end
8
+ def self.install(package, *args)
9
+ system "winget", "install", *args, "--id=#{package}", "-e"
10
+ end
12
11
 
13
- def self.update(*args)
14
- return system 'winget', 'upgrade'
12
+ def self.update(*_args)
13
+ system "winget", "upgrade"
14
+ end
15
15
 
16
- end
17
-
18
- def self.uninstall(package, *args)
19
- return system 'winget', 'uninstall', *args, "--id=#{package}", "-e"
20
- end
21
- end
16
+ def self.uninstall(package, *args)
17
+ system "winget", "uninstall", *args, "--id=#{package}", "-e"
18
+ end
19
+ end
data/lib/pkg/pkgm/yay.rb CHANGED
@@ -1,18 +1,17 @@
1
-
2
1
  class Yay
3
- def self.install_all(packages, *args)
4
- return system 'yay', '-Sy', *args, *packages
5
- end
2
+ def self.install_all(packages, *args)
3
+ system "yay", "-Sy", *args, *packages
4
+ end
6
5
 
7
- def self.install(package, *args)
8
- return system 'yay', '-Sy', *args, package
9
- end
6
+ def self.install(package, *args)
7
+ system "yay", "-Sy", *args, package
8
+ end
10
9
 
11
- def self.update(*args)
12
- return system 'yay', '-Syu', *args
13
- end
10
+ def self.update(*args)
11
+ system "yay", "-Syu", *args
12
+ end
14
13
 
15
- def self.uninstall(package, *args)
16
- return system 'yay', '-R', *args, package
17
- end
18
- end
14
+ def self.uninstall(package, *args)
15
+ system "yay", "-R", *args, package
16
+ end
17
+ end
@@ -1,27 +1,27 @@
1
1
  class FileUtil
2
- USER_HOME = 'user-home'
2
+ USER_HOME = "user-home".freeze
3
3
 
4
- def self.to_local_file(file)
5
- local_file = File.absolute_path(file.dup)
4
+ def self.to_local_file(file)
5
+ local_file = File.absolute_path(file.dup)
6
6
 
7
- if local_file.include? Dir.home
8
- local_file[Dir.home] = USER_HOME
9
- elsif local_file.start_with?("/")
10
- local_file = local_file[1..-1]
11
- end
12
-
13
- return local_file
7
+ if local_file.include? Dir.home
8
+ local_file[Dir.home] = USER_HOME
9
+ elsif local_file.start_with?("/")
10
+ local_file = local_file[1..]
14
11
  end
15
12
 
16
- def self.to_system_file(file)
17
- system_file = file.dup
13
+ local_file
14
+ end
18
15
 
19
- if system_file.start_with? USER_HOME
20
- system_file[USER_HOME] = Dir.home
21
- else
22
- system_file = "/#{system_file}"
23
- end
16
+ def self.to_system_file(file)
17
+ system_file = file.dup
24
18
 
25
- return system_file
19
+ if system_file.start_with? USER_HOME
20
+ system_file[USER_HOME] = Dir.home
21
+ else
22
+ system_file = "/#{system_file}"
26
23
  end
27
- end
24
+
25
+ system_file
26
+ end
27
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ # module Cmt
2
+ VERSION = "0.0.3".freeze
3
+ # end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
- - Simon Schuster
8
- autorequire:
7
+ - simon.schuster
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-06 00:00:00.000000000 Z
11
+ date: 2023-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -25,7 +25,8 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.2'
27
27
  description: "[C]onfiguration [M]anagment [T]ool"
28
- email: simon.schuster@outlook.com
28
+ email:
29
+ - simon.schuster@dynatrace.com
29
30
  executables:
30
31
  - cmt
31
32
  extensions: []
@@ -39,17 +40,24 @@ files:
39
40
  - lib/dotfiles/dotfiles_cli.rb
40
41
  - lib/pkg/pkg.rb
41
42
  - lib/pkg/pkg_config.rb
43
+ - lib/pkg/pkgm/dnf.rb
42
44
  - lib/pkg/pkgm/pacman.rb
43
45
  - lib/pkg/pkgm/pip.rb
44
46
  - lib/pkg/pkgm/snap.rb
45
47
  - lib/pkg/pkgm/winget.rb
46
48
  - lib/pkg/pkgm/yay.rb
47
49
  - lib/util/file_util.rb
48
- homepage: https://github.com/kpurdon/rumr
50
+ - lib/version.rb
51
+ homepage: https://github.com/Setre14/cmt
49
52
  licenses:
50
- - GPLv3
51
- metadata: {}
52
- post_install_message:
53
+ - MIT
54
+ metadata:
55
+ allowed_push_host: https://rubygems.org/
56
+ homepage_uri: https://github.com/Setre14/cmt
57
+ source_code_uri: https://github.com/Setre14/cmt
58
+ changelog_uri: https://github.com/Setre14/cmt/blob/main/CHANGELOG.md
59
+ rubygems_mfa_required: 'true'
60
+ post_install_message:
53
61
  rdoc_options: []
54
62
  require_paths:
55
63
  - lib
@@ -57,15 +65,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
65
  requirements:
58
66
  - - ">="
59
67
  - !ruby/object:Gem::Version
60
- version: '0'
68
+ version: 2.7.0
61
69
  required_rubygems_version: !ruby/object:Gem::Requirement
62
70
  requirements:
63
71
  - - ">="
64
72
  - !ruby/object:Gem::Version
65
73
  version: '0'
66
74
  requirements: []
67
- rubygems_version: 3.3.26
68
- signing_key:
75
+ rubygems_version: 3.3.5
76
+ signing_key:
69
77
  specification_version: 4
70
78
  summary: configuration managment tool
71
79
  test_files: []