cmt 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cmt.rb +35 -24
- data/lib/config/config.rb +5 -5
- data/lib/config/git_config.rb +12 -28
- data/lib/{dotfiles/dotfiles.rb → env/env.rb} +18 -17
- data/lib/env/env_cli.rb +25 -0
- data/lib/pkg/pkg.rb +60 -79
- data/lib/pkg/pkg_config.rb +35 -13
- data/lib/pkg/pkgm/dnf.rb +42 -9
- data/lib/pkg/pkgm/pacman.rb +22 -10
- data/lib/pkg/pkgm/pip.rb +24 -11
- data/lib/pkg/pkgm/snap.rb +24 -11
- data/lib/pkg/pkgm/winget.rb +24 -12
- data/lib/pkg/pkgm/yay.rb +22 -10
- data/lib/util/file_util.rb +2 -2
- data/lib/util/log.rb +9 -0
- data/lib/version.rb +1 -1
- metadata +5 -4
- data/lib/dotfiles/dotfiles_cli.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea63de6b8dc974f078ebfb115a23e601e6d9b532dba46aac1d35e8ad099fee79
|
4
|
+
data.tar.gz: 4ae37db6d7f02c28790feb78d0e1202941c8b9f8e5be6a6bb019cbc43665cc04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73a5ec835865a020fb23edb0f28c83e43f83b8828efc621f041be0a4781c224d671b5145c5f991637089050ee0a21867107ee7dcd4205ce194a4436532743e68
|
7
|
+
data.tar.gz: 5694d4e88cf8f841dc088e3828dea22393e926bffe2ce58dccf0da7fa16156932960577148bb4f0c63078c4fd5a34930b4c017a8c79cc59ee62b81589b72d425
|
data/lib/cmt.rb
CHANGED
@@ -1,31 +1,42 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
6
|
-
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
10
|
-
require_relative
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
1
|
+
require 'thor'
|
2
|
+
require 'pathname'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
require_relative 'config/git_config'
|
7
|
+
require_relative 'env/env_cli'
|
8
|
+
require_relative 'pkg/pkg'
|
9
|
+
require_relative 'util/log'
|
10
|
+
require_relative 'version'
|
11
|
+
|
12
|
+
class Cmt < Pkg
|
13
|
+
desc 'init', 'Init'
|
14
|
+
option :force, type: :boolean, default: false
|
15
|
+
def init(repo)
|
16
|
+
force = options['force']
|
17
|
+
|
18
|
+
if File.exist? $CONFIG_DIR
|
19
|
+
if force
|
20
|
+
FileUtils.rm_rf($CONFIG_DIR)
|
21
|
+
else
|
22
|
+
Log::LOGGER.error("Config already exists at '#{$CONFIG_DIR}'")
|
23
|
+
abort("Config already exists at '#{$CONFIG_DIR}'")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
`git clone #{repo} #{$CONFIG_DIR}`
|
28
|
+
end
|
17
29
|
|
18
|
-
|
19
|
-
|
20
|
-
subcommand "config", GitConfig
|
30
|
+
desc 'config SUBCOMMAND ...ARGS', 'manage set of tracked repositories'
|
31
|
+
subcommand 'config', GitConfig
|
21
32
|
|
22
|
-
desc
|
23
|
-
subcommand
|
33
|
+
desc 'env SUBCOMMAND ...ARGS', 'manage set of tracked repositories'
|
34
|
+
subcommand 'env', EnvCli
|
24
35
|
|
25
|
-
desc "pkg SUBCOMMAND ...ARGS", "manage set of tracked repositories"
|
26
|
-
subcommand "pkg", Pkg
|
36
|
+
# desc "pkg SUBCOMMAND ...ARGS", "manage set of tracked repositories"
|
37
|
+
# subcommand "pkg", Pkg
|
27
38
|
|
28
|
-
desc
|
39
|
+
desc 'version', 'Print version'
|
29
40
|
def version
|
30
41
|
puts(VERSION)
|
31
42
|
end
|
data/lib/config/config.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'thor'
|
2
|
+
require 'fileutils'
|
3
3
|
|
4
|
-
$CONFIG_DIR = File.join(Dir.home,
|
4
|
+
$CONFIG_DIR = File.join(Dir.home, '.config', 'cmt')
|
5
5
|
|
6
6
|
class Config
|
7
7
|
def self.get_config_json(file, default_config)
|
8
8
|
FileUtils.mkdir_p File.dirname(file)
|
9
|
-
File.write(file, JSON.pretty_generate(default_config, { indent:
|
9
|
+
File.write(file, JSON.pretty_generate(default_config, { indent: ' ' })) unless File.exist?(file)
|
10
10
|
|
11
11
|
config = JSON.load_file(file)
|
12
12
|
default_config.merge(config)
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.write_config_file(file, config)
|
16
|
-
File.write(file, JSON.pretty_generate(config, { indent:
|
16
|
+
File.write(file, JSON.pretty_generate(config, { indent: ' ' }))
|
17
17
|
end
|
18
18
|
end
|
data/lib/config/git_config.rb
CHANGED
@@ -1,27 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require 'thor'
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative 'config'
|
4
|
+
require_relative '../util/log'
|
4
5
|
|
5
6
|
class GitConfig < Thor
|
6
|
-
desc
|
7
|
-
option :
|
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"
|
7
|
+
desc 'update', 'update'
|
8
|
+
option :message, default: 'Update config'
|
25
9
|
def update
|
26
10
|
message = options['message']
|
27
11
|
Dir.chdir($CONFIG_DIR) do
|
@@ -29,10 +13,10 @@ class GitConfig < Thor
|
|
29
13
|
num_changes = changes.split.length
|
30
14
|
|
31
15
|
if num_changes.zero?
|
32
|
-
|
16
|
+
Log::LOGGER.error("No changes to commit in '#{$CONFIG_DIR}'")
|
33
17
|
abort("No changes to commit in '#{$CONFIG_DIR}'")
|
34
18
|
else
|
35
|
-
|
19
|
+
Log::LOGGER.info('Commit changes')
|
36
20
|
system 'git', 'add', '.'
|
37
21
|
system 'git', 'commit', '-m', "'#{message}'"
|
38
22
|
system 'git', 'push'
|
@@ -40,30 +24,30 @@ class GitConfig < Thor
|
|
40
24
|
end
|
41
25
|
end
|
42
26
|
|
43
|
-
desc
|
27
|
+
desc 'status', "Show git status in '#{$CONFIG_DIR}'"
|
44
28
|
def status(*args)
|
45
29
|
Dir.chdir($CONFIG_DIR) do
|
46
30
|
system 'git', 'status', *args
|
47
31
|
end
|
48
32
|
end
|
49
33
|
|
50
|
-
desc
|
34
|
+
desc 'pull', "Pull newest changes in '#{$CONFIG_DIR}'"
|
51
35
|
def pull(*args)
|
52
36
|
Dir.chdir($CONFIG_DIR) do
|
53
37
|
system 'git', 'pull', *args
|
54
38
|
end
|
55
39
|
end
|
56
40
|
|
57
|
-
desc
|
41
|
+
desc 'exec', "Execute any git command in '#{$CONFIG_DIR}'"
|
58
42
|
def exec(*args)
|
59
43
|
Dir.chdir($CONFIG_DIR) do
|
60
44
|
system 'git', *args
|
61
45
|
end
|
62
46
|
end
|
63
47
|
|
64
|
-
desc
|
48
|
+
desc 'code', "Open '#{$CONFIG_DIR}' in code"
|
65
49
|
def code(*args)
|
66
|
-
|
50
|
+
Log::LOGGER.info("Open '#{$CONFIG_DIR}' in code")
|
67
51
|
Dir.chdir($CONFIG_DIR) do
|
68
52
|
system 'code', '.', *args
|
69
53
|
end
|
@@ -1,22 +1,23 @@
|
|
1
|
-
require
|
1
|
+
require 'thor'
|
2
2
|
require 'pathname'
|
3
3
|
require 'fileutils'
|
4
4
|
require 'json'
|
5
|
-
require
|
5
|
+
require 'logger'
|
6
6
|
|
7
7
|
require_relative '../config/config'
|
8
8
|
require_relative '../util/file_util'
|
9
|
+
require_relative '../util/log'
|
9
10
|
|
10
|
-
class
|
11
|
-
CONFIG_SUB_DIR = '
|
11
|
+
class Env
|
12
|
+
CONFIG_SUB_DIR = 'env'.freeze
|
12
13
|
ROOT_PATH = File.join($CONFIG_DIR, CONFIG_SUB_DIR).freeze
|
13
|
-
CONFIG_FILE = File.join(ROOT_PATH, '
|
14
|
+
CONFIG_FILE = File.join(ROOT_PATH, 'env.json').freeze
|
14
15
|
FILES_PATH = File.join(ROOT_PATH, 'files').freeze
|
15
16
|
FOLDERS_PATH = File.join(ROOT_PATH, 'folders').freeze
|
16
17
|
|
17
18
|
DEFAULT_CONFIG = {
|
18
|
-
|
19
|
-
|
19
|
+
'files' => [],
|
20
|
+
'folders' => []
|
20
21
|
}.freeze
|
21
22
|
|
22
23
|
def add(file)
|
@@ -47,7 +48,7 @@ class Dotfiles
|
|
47
48
|
|
48
49
|
Config.write_config_file(CONFIG_FILE, config)
|
49
50
|
|
50
|
-
|
51
|
+
Log::LOGGER.info("Added '#{parsed_file}'")
|
51
52
|
end
|
52
53
|
|
53
54
|
def remove(file)
|
@@ -66,11 +67,11 @@ class Dotfiles
|
|
66
67
|
|
67
68
|
Config.write_config_file(CONFIG_FILE, config)
|
68
69
|
|
69
|
-
|
70
|
+
Log::LOGGER.info("Removed '#{local_file}'")
|
70
71
|
end
|
71
72
|
|
72
73
|
def apply
|
73
|
-
|
74
|
+
Log::LOGGER.info('Start apply')
|
74
75
|
|
75
76
|
config = Config.get_config_json(CONFIG_FILE, DEFAULT_CONFIG)
|
76
77
|
files = config['files']
|
@@ -79,7 +80,7 @@ class Dotfiles
|
|
79
80
|
dest_file = FileUtil.to_system_file(file)
|
80
81
|
|
81
82
|
abs_file = File.join(FILES_PATH, file)
|
82
|
-
|
83
|
+
Log::LOGGER.debug("Copy #{abs_file} to #{dest_file}")
|
83
84
|
|
84
85
|
FileUtils.cp_r(abs_file, dest_file, remove_destination: true)
|
85
86
|
end
|
@@ -90,16 +91,16 @@ class Dotfiles
|
|
90
91
|
dest_file = File.dirname(FileUtil.to_system_file(folder))
|
91
92
|
|
92
93
|
abs_file = File.join(FOLDERS_PATH, folder)
|
93
|
-
|
94
|
+
Log::LOGGER.debug("Copy #{abs_file} to #{dest_file}")
|
94
95
|
|
95
96
|
FileUtils.cp_r(abs_file, dest_file, remove_destination: true)
|
96
97
|
end
|
97
98
|
|
98
|
-
|
99
|
+
Log::LOGGER.info('Finished apply')
|
99
100
|
end
|
100
101
|
|
101
102
|
def sync
|
102
|
-
|
103
|
+
Log::LOGGER.info('Start sync')
|
103
104
|
|
104
105
|
config = Config.get_config_json(CONFIG_FILE, DEFAULT_CONFIG)
|
105
106
|
files = config['files']
|
@@ -108,7 +109,7 @@ class Dotfiles
|
|
108
109
|
dest_file = FileUtil.to_system_file(file)
|
109
110
|
|
110
111
|
abs_file = File.join(FILES_PATH, file)
|
111
|
-
|
112
|
+
Log::LOGGER.debug("Copy #{dest_file} to #{abs_file}")
|
112
113
|
|
113
114
|
FileUtils.cp_r(dest_file, abs_file, remove_destination: true)
|
114
115
|
end
|
@@ -119,12 +120,12 @@ class Dotfiles
|
|
119
120
|
dest_file = FileUtil.to_system_file(folder)
|
120
121
|
|
121
122
|
abs_file = File.dirname(File.join(FOLDERS_PATH, folder))
|
122
|
-
|
123
|
+
Log::LOGGER.debug("Copy #{dest_file} to #{abs_file}")
|
123
124
|
|
124
125
|
FileUtils.cp_r(dest_file, abs_file, remove_destination: true)
|
125
126
|
end
|
126
127
|
|
127
|
-
|
128
|
+
Log::LOGGER.info('Finished sync')
|
128
129
|
end
|
129
130
|
|
130
131
|
def get_local_path(file)
|
data/lib/env/env_cli.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'env'
|
2
|
+
|
3
|
+
class EnvCli < Thor
|
4
|
+
ENV = Env.new
|
5
|
+
|
6
|
+
desc 'add <file>', 'Add file/folder to sync'
|
7
|
+
def add(file)
|
8
|
+
ENV.add(file)
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'remove <file>', 'Remove file/folder from sync'
|
12
|
+
def remove(file)
|
13
|
+
ENV.remove(file)
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'apply', 'Copies all env defined in the user config to the system'
|
17
|
+
def apply
|
18
|
+
ENV.apply
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'sync', 'Updates all files defined in the user config from the system to the config dir'
|
22
|
+
def sync
|
23
|
+
ENV.sync
|
24
|
+
end
|
25
|
+
end
|
data/lib/pkg/pkg.rb
CHANGED
@@ -1,104 +1,85 @@
|
|
1
|
-
require
|
1
|
+
require 'thor'
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
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'
|
10
|
+
|
11
|
+
require_relative '../util/log'
|
10
12
|
|
11
13
|
class Pkg < Thor
|
12
14
|
SYSTEM_PACKAGE_MANGER = {
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
'manjaro' => 'pacman',
|
16
|
+
'fedora' => 'dnf',
|
17
|
+
'windows' => 'winget'
|
16
18
|
}.freeze
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
PACKAGE_MANGER = {
|
20
|
+
'pacman' => Pacman,
|
21
|
+
'dnf' => Dnf,
|
22
|
+
'winget' => Winget,
|
23
|
+
'pip' => Pip,
|
24
|
+
'snap' => Snap,
|
25
|
+
'yay' => Yay
|
21
26
|
}.freeze
|
22
|
-
RELEASE_FILE =
|
27
|
+
RELEASE_FILE = '/etc/os-release'.freeze
|
23
28
|
|
24
|
-
desc "install_all", "Install"
|
25
|
-
option "pkgm", default: "system"
|
26
|
-
def install_all(*args)
|
27
|
-
|
29
|
+
# desc "install_all", "Install"
|
30
|
+
# option "pkgm", default: "system"
|
31
|
+
# def install_all(*args)
|
32
|
+
# manager = Pkg.get_package_manager(options["pkgm"])
|
28
33
|
|
29
|
-
|
30
|
-
|
34
|
+
# config_file = PkgConfig.get_config_file(manager)
|
35
|
+
# config = Config.get_config_json(config_file, PkgConfig.default_config)
|
31
36
|
|
32
|
-
|
37
|
+
# packages = config["packages"]
|
33
38
|
|
34
|
-
|
35
|
-
end
|
39
|
+
# manager.install_all(packages, *args)
|
40
|
+
# end
|
36
41
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
manager = get_package_manager(options["pkgm"])
|
42
|
+
def self.get_package_manager(pkgm)
|
43
|
+
pkgm = Pkg.get_system_package_manager unless pkgm != 'system'
|
44
|
+
manager = PACKAGE_MANGER[pkgm]
|
41
45
|
|
42
|
-
|
46
|
+
if manager.nil?
|
47
|
+
Log::LOGGER.error("'#{pkgm}' is not supported")
|
48
|
+
abort("'#{pkgm}' is not supported")
|
49
|
+
end
|
43
50
|
|
44
|
-
|
51
|
+
Log::LOGGER.info("Using package manager '#{manager}'")
|
45
52
|
|
46
|
-
|
53
|
+
manager
|
47
54
|
end
|
48
55
|
|
49
|
-
|
50
|
-
|
51
|
-
def update(*args)
|
52
|
-
manager = get_package_manager(options["pkgm"])
|
56
|
+
def self.get_system_package_manager
|
57
|
+
manager = nil
|
53
58
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
if Gem.win_platform?
|
60
|
+
manager = SYSTEM_PACKAGE_MANGER['windows']
|
61
|
+
else
|
62
|
+
r = { 'distro' => nil }
|
63
|
+
unless File.exist?(RELEASE_FILE)
|
64
|
+
Log::LOGGER.error("'#{RELEASE_FILE}' does not exist")
|
65
|
+
abort("'#{RELEASE_FILE}' does not exist")
|
66
|
+
end
|
61
67
|
|
62
|
-
|
68
|
+
File.foreach(RELEASE_FILE) do |line|
|
69
|
+
r = { 'distro' => ::Regexp.last_match(1) } if line =~ /^ID=(.*)/
|
70
|
+
end
|
63
71
|
|
64
|
-
|
72
|
+
manager = SYSTEM_PACKAGE_MANGER[r['distro']]
|
73
|
+
end
|
65
74
|
|
66
|
-
|
75
|
+
return manager
|
67
76
|
end
|
68
77
|
|
69
|
-
|
70
|
-
|
71
|
-
manager = nil
|
72
|
-
|
73
|
-
if pkgm == "system"
|
74
|
-
|
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
|
-
|
84
|
-
File.foreach(RELEASE_FILE) do |line|
|
85
|
-
r = { "distro" => ::Regexp.last_match(1) } if line =~ /^ID=(.*)/
|
86
|
-
end
|
87
|
-
|
88
|
-
manager = SYSTEM_PACKAGE_MANGER[r["distro"]]
|
89
|
-
end
|
90
|
-
else
|
91
|
-
manager = OTHER_PACKAGE_MANGER[pkgm]
|
92
|
-
end
|
93
|
-
|
94
|
-
if manager.nil?
|
95
|
-
$logger.error("'#{pkgm}' is not supported")
|
96
|
-
abort("'#{pkgm}' is not supported")
|
97
|
-
end
|
98
|
-
|
99
|
-
$logger.info("Using package manager '#{manager}'")
|
78
|
+
desc 'system SUBCOMMAND ...ARGS', 'manage system packages'
|
79
|
+
subcommand 'system', Pkg.get_package_manager('system')
|
100
80
|
|
101
|
-
|
102
|
-
|
81
|
+
PACKAGE_MANGER.each do |key, value|
|
82
|
+
desc "#{key} SUBCOMMAND ...ARGS", "manage #{key} packages"
|
83
|
+
subcommand key, value
|
103
84
|
end
|
104
85
|
end
|
data/lib/pkg/pkg_config.rb
CHANGED
@@ -1,41 +1,63 @@
|
|
1
|
-
require
|
1
|
+
require 'json'
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative '../config/config'
|
4
|
+
require_relative '../util/log'
|
5
|
+
|
6
|
+
module ConfigOptions
|
7
|
+
PACKAGES = 'packages'.freeze
|
8
|
+
REMOTES = 'remotes'.freeze
|
9
|
+
REPOS = 'repos'.freeze
|
10
|
+
end
|
4
11
|
|
5
12
|
class PkgConfig
|
6
|
-
CONFIG_SUB_DIR =
|
13
|
+
CONFIG_SUB_DIR = 'pkg'.freeze
|
7
14
|
ROOT_PATH = File.join($CONFIG_DIR, CONFIG_SUB_DIR).freeze
|
8
15
|
DEFAULT_CONFIG = {
|
9
|
-
|
10
|
-
|
16
|
+
ConfigOptions::PACKAGES => [],
|
17
|
+
ConfigOptions::REMOTES => [],
|
18
|
+
ConfigOptions::REPOS => []
|
11
19
|
}.freeze
|
12
20
|
|
13
|
-
def self.add(pkgm,
|
21
|
+
def self.add(pkgm, config_option, item, success)
|
22
|
+
unless success
|
23
|
+
Log::LOGGER.error("#{config_option[1..]} '#{item}' could not be added")
|
24
|
+
abort
|
25
|
+
end
|
26
|
+
|
14
27
|
config_file = PkgConfig.get_config_file(pkgm)
|
28
|
+
Log::LOGGER.info("Add '#{item}' to list '#{config_option}' in '#{config_file}")
|
15
29
|
|
16
30
|
config = Config.get_config_json(config_file, DEFAULT_CONFIG)
|
17
31
|
|
18
|
-
|
32
|
+
puts(config)
|
19
33
|
|
20
|
-
|
34
|
+
list = config[config_option]
|
35
|
+
list.append item unless list.include? item
|
36
|
+
config[config_option] = list.sort
|
21
37
|
|
22
38
|
Config.write_config_file(config_file, config)
|
23
39
|
end
|
24
40
|
|
25
|
-
def self.remove(pkgm,
|
41
|
+
def self.remove(pkgm, config_option, item, success)
|
42
|
+
unless success
|
43
|
+
Log::LOGGER.error("#{config_option[1..]} '#{item}' could not be removed")
|
44
|
+
abort
|
45
|
+
end
|
46
|
+
|
26
47
|
config_file = PkgConfig.get_config_file(pkgm)
|
48
|
+
Log::LOGGER.info("Remove '#{item}' from list '#{config_option}' in '#{config_file}")
|
27
49
|
|
28
50
|
config = Config.get_config_json(config_file, DEFAULT_CONFIG)
|
29
51
|
|
30
|
-
|
31
|
-
|
32
|
-
|
52
|
+
list = config[config_option]
|
53
|
+
list.delete item if list.include? item
|
54
|
+
config[config_option] = list.sort
|
33
55
|
|
34
56
|
Config.write_config_file(config_file, config)
|
35
57
|
end
|
36
58
|
|
37
59
|
def self.get_config_file(pkgm)
|
38
|
-
pkgm = pkgm.downcase
|
60
|
+
pkgm = pkgm.to_s.downcase
|
39
61
|
File.join(ROOT_PATH, "#{pkgm}.json")
|
40
62
|
end
|
41
63
|
|
data/lib/pkg/pkgm/dnf.rb
CHANGED
@@ -1,17 +1,50 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
require_relative '../pkg_config'
|
4
|
+
|
5
|
+
class Dnf < Thor
|
6
|
+
desc 'add_repo', 'Add repository'
|
7
|
+
def add_repo(repo)
|
8
|
+
system 'sudo', 'dnf', 'install', '-y', 'dnf-plugins-core'
|
9
|
+
success = system 'sudo', 'dnf', 'config-manager', '--add-repo', repo
|
10
|
+
|
11
|
+
PkgConfig.add(self.class.name, ConfigOptions::REPOS, repo, success)
|
4
12
|
end
|
5
13
|
|
6
|
-
|
7
|
-
|
14
|
+
desc 'remove_repo', 'Remove repository'
|
15
|
+
def remove_repo(repo, url)
|
16
|
+
system 'sudo', 'dnf', 'install', '-y', 'dnf-plugins-core'
|
17
|
+
success = system 'sudo', 'dnf', 'config-manager', '--set-disabled', repo
|
18
|
+
|
19
|
+
PkgConfig.remove(self.class.name, ConfigOptions::REPOS, url, success)
|
8
20
|
end
|
9
21
|
|
10
|
-
|
11
|
-
|
22
|
+
desc 'list_repos', 'List repos'
|
23
|
+
def list_repos
|
24
|
+
system 'dnf', 'repolist', 'enabled'
|
12
25
|
end
|
13
26
|
|
14
|
-
|
15
|
-
|
27
|
+
# desc "install_all", "Install all"
|
28
|
+
# def install_all(packages, *args)
|
29
|
+
# system "sudo", "dnf", "install", *args, *packages
|
30
|
+
# end
|
31
|
+
|
32
|
+
desc 'install', 'Install'
|
33
|
+
def install(package, *args)
|
34
|
+
success = system 'sudo', 'dnf', 'install', *args, package
|
35
|
+
|
36
|
+
PkgConfig.add(self.class.name, ConfigOptions::PACKAGES, package, success)
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'update', 'update'
|
40
|
+
def update(*args)
|
41
|
+
system 'sudo', 'dnf', 'update', *args
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'uninstall', 'Uninstall'
|
45
|
+
def uninstall(package, *args)
|
46
|
+
success = system 'sudo', 'dnf', 'remove', *args, package
|
47
|
+
|
48
|
+
PkgConfig.remove(self.class.name, ConfigOptions::PACKAGES, package, success)
|
16
49
|
end
|
17
50
|
end
|
data/lib/pkg/pkgm/pacman.rb
CHANGED
@@ -1,17 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
require_relative '../pkg_config'
|
4
|
+
|
5
|
+
class Pacman < Thor
|
6
|
+
# desc "install_all", "Install all"
|
7
|
+
# def install_all(packages, *args)
|
8
|
+
# system "sudo", "pacman", "-Sy", *args, *packages
|
9
|
+
# end
|
5
10
|
|
6
|
-
|
7
|
-
|
11
|
+
desc 'install', 'Install'
|
12
|
+
def install(package, *args)
|
13
|
+
success = system 'sudo', 'pacman', '-Sy', *args, package
|
14
|
+
|
15
|
+
PkgConfig.add(self.class.name, ConfigOptions::PACKAGES, package, success)
|
8
16
|
end
|
9
17
|
|
10
|
-
|
11
|
-
|
18
|
+
desc 'update', 'update'
|
19
|
+
def update(*args)
|
20
|
+
system 'sudo', 'pacman', '-Syu', *args
|
12
21
|
end
|
13
22
|
|
14
|
-
|
15
|
-
|
23
|
+
desc 'uninstall', 'Uninstall'
|
24
|
+
def uninstall(package, *args)
|
25
|
+
success = system 'sudo', 'pacman', '-R', *args, package
|
26
|
+
|
27
|
+
PkgConfig.remove(self.class.name, ConfigOptions::PACKAGES, package, success)
|
16
28
|
end
|
17
29
|
end
|
data/lib/pkg/pkgm/pip.rb
CHANGED
@@ -1,18 +1,31 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
require_relative '../pkg_config'
|
4
|
+
require_relative '../../util/log'
|
5
|
+
|
6
|
+
class Pip < Thor
|
7
|
+
# desc "install_all", "Install all"
|
8
|
+
# def install_all(packages, *args)
|
9
|
+
# system "python3", "-m", "pip", "install", *args, *packages
|
10
|
+
# end
|
5
11
|
|
6
|
-
|
7
|
-
|
12
|
+
desc 'install', 'Install'
|
13
|
+
def install(package, *args)
|
14
|
+
success = system 'python3', '-m', 'pip', 'install', *args, package
|
15
|
+
|
16
|
+
PkgConfig.add(self.class.name, ConfigOptions::PACKAGES, package, success)
|
8
17
|
end
|
9
18
|
|
10
|
-
|
11
|
-
|
12
|
-
|
19
|
+
desc 'update', 'update'
|
20
|
+
def update(*_args)
|
21
|
+
Log::LOGGER.error('Update is not supported for pip')
|
22
|
+
abort('Update is not supported for pip')
|
13
23
|
end
|
14
24
|
|
15
|
-
|
16
|
-
|
25
|
+
desc 'uninstall', 'Uninstall'
|
26
|
+
def uninstall(package, *args)
|
27
|
+
success = system 'python3', '-m', 'pip', 'uninstall', *args, package
|
28
|
+
|
29
|
+
PkgConfig.remove(self.class.name, ConfigOptions::PACKAGES, package, success)
|
17
30
|
end
|
18
31
|
end
|
data/lib/pkg/pkgm/snap.rb
CHANGED
@@ -1,18 +1,31 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
require_relative '../pkg_config'
|
4
|
+
require_relative '../../util/log'
|
5
|
+
|
6
|
+
class Snap < Thor
|
7
|
+
# desc "install_all", "Install all"
|
8
|
+
# def install_all(packages, *args)
|
9
|
+
# system "snap", "install", *args, *packages
|
10
|
+
# end
|
5
11
|
|
6
|
-
|
7
|
-
|
12
|
+
desc 'install', 'Install'
|
13
|
+
def install(package, *args)
|
14
|
+
success = system 'snap', 'install', *args, package
|
15
|
+
|
16
|
+
PkgConfig.add(self.class.name, ConfigOptions::PACKAGES, package, success)
|
8
17
|
end
|
9
18
|
|
10
|
-
|
11
|
-
|
12
|
-
|
19
|
+
desc 'update', 'update'
|
20
|
+
def update(*_args)
|
21
|
+
Log::LOGGER.error('Update is not supported for snap')
|
22
|
+
abort('Update is not supported for snap')
|
13
23
|
end
|
14
24
|
|
15
|
-
|
16
|
-
|
25
|
+
desc 'uninstall', 'Uninstall'
|
26
|
+
def uninstall(package, *args)
|
27
|
+
success = system 'snap', 'remove', *args, package
|
28
|
+
|
29
|
+
PkgConfig.remove(self.class.name, ConfigOptions::PACKAGES, package, success)
|
17
30
|
end
|
18
31
|
end
|
data/lib/pkg/pkgm/winget.rb
CHANGED
@@ -1,19 +1,31 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
require_relative '../pkg_config'
|
4
|
+
|
5
|
+
class Winget < Thor
|
6
|
+
# desc "install_all", "Install all"
|
7
|
+
# def install_all(packages, *args)
|
8
|
+
# packages.each do |package|
|
9
|
+
# Winget.install(package, *args)
|
10
|
+
# end
|
11
|
+
# end
|
7
12
|
|
8
|
-
|
9
|
-
|
13
|
+
desc 'install', 'Install'
|
14
|
+
def install(package, *args)
|
15
|
+
success = system 'winget', 'install', *args, "--id=#{package}", '-e'
|
16
|
+
|
17
|
+
PkgConfig.add(self.class.name, ConfigOptions::PACKAGES, package, success)
|
10
18
|
end
|
11
19
|
|
12
|
-
|
13
|
-
|
20
|
+
desc 'update', 'update'
|
21
|
+
def update(*_args)
|
22
|
+
system 'winget', 'upgrade'
|
14
23
|
end
|
15
24
|
|
16
|
-
|
17
|
-
|
25
|
+
desc 'uninstall', 'Uninstall'
|
26
|
+
def uninstall(package, *args)
|
27
|
+
success = system 'winget', 'uninstall', *args, "--id=#{package}", '-e'
|
28
|
+
|
29
|
+
PkgConfig.remove(self.class.name, ConfigOptions::PACKAGES, package, success)
|
18
30
|
end
|
19
31
|
end
|
data/lib/pkg/pkgm/yay.rb
CHANGED
@@ -1,17 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
require_relative '../pkg_config'
|
4
|
+
|
5
|
+
class Yay < Thor
|
6
|
+
# desc "install_all", "Install all"
|
7
|
+
# def install_all(packages, *args)
|
8
|
+
# system "yay", "-Sy", *args, *packages
|
9
|
+
# end
|
5
10
|
|
6
|
-
|
7
|
-
|
11
|
+
desc 'install', 'Install'
|
12
|
+
def install(package, *args)
|
13
|
+
success = system 'yay', '-Sy', *args, package
|
14
|
+
|
15
|
+
PkgConfig.add(self.class.name, ConfigOptions::PACKAGES, package, success)
|
8
16
|
end
|
9
17
|
|
10
|
-
|
11
|
-
|
18
|
+
desc 'update', 'update'
|
19
|
+
def update(*args)
|
20
|
+
system 'yay', '-Syu', *args
|
12
21
|
end
|
13
22
|
|
14
|
-
|
15
|
-
|
23
|
+
desc 'uninstall', 'Uninstall'
|
24
|
+
def uninstall(package, *args)
|
25
|
+
success = system 'yay', '-R', *args, package
|
26
|
+
|
27
|
+
PkgConfig.remove(self.class.name, ConfigOptions::PACKAGES, package, success)
|
16
28
|
end
|
17
29
|
end
|
data/lib/util/file_util.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
class FileUtil
|
2
|
-
USER_HOME =
|
2
|
+
USER_HOME = 'user-home'.freeze
|
3
3
|
|
4
4
|
def self.to_local_file(file)
|
5
5
|
local_file = File.absolute_path(file.dup)
|
6
6
|
|
7
7
|
if local_file.include? Dir.home
|
8
8
|
local_file[Dir.home] = USER_HOME
|
9
|
-
elsif local_file.start_with?(
|
9
|
+
elsif local_file.start_with?('/')
|
10
10
|
local_file = local_file[1..]
|
11
11
|
end
|
12
12
|
|
data/lib/util/log.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Log
|
4
|
+
LOGGER = Logger.new($stdout)
|
5
|
+
LOGGER.formatter = proc do |severity, datetime, _progname, msg|
|
6
|
+
date_format = datetime.strftime('%Y-%m-%d %H:%M:%S')
|
7
|
+
JSON.dump(date: date_format, severity: severity.ljust(5), pid: "##{Process.pid}", message: msg) + "\n" # rubocop:disable Style/StringConcatenation
|
8
|
+
end
|
9
|
+
end
|
data/lib/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- simon.schuster
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -36,8 +36,8 @@ files:
|
|
36
36
|
- lib/cmt.rb
|
37
37
|
- lib/config/config.rb
|
38
38
|
- lib/config/git_config.rb
|
39
|
-
- lib/
|
40
|
-
- lib/
|
39
|
+
- lib/env/env.rb
|
40
|
+
- lib/env/env_cli.rb
|
41
41
|
- lib/pkg/pkg.rb
|
42
42
|
- lib/pkg/pkg_config.rb
|
43
43
|
- lib/pkg/pkgm/dnf.rb
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- lib/pkg/pkgm/winget.rb
|
48
48
|
- lib/pkg/pkgm/yay.rb
|
49
49
|
- lib/util/file_util.rb
|
50
|
+
- lib/util/log.rb
|
50
51
|
- lib/version.rb
|
51
52
|
homepage: https://github.com/Setre14/cmt
|
52
53
|
licenses:
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require_relative "dotfiles"
|
2
|
-
|
3
|
-
class DotfilesCli < Thor
|
4
|
-
DOTFILES = Dotfiles.new
|
5
|
-
|
6
|
-
desc "init", "Download objects and refs from another repository"
|
7
|
-
def init
|
8
|
-
DOTFILES.init
|
9
|
-
end
|
10
|
-
|
11
|
-
desc "add <file>", "Download objects and refs from another repository"
|
12
|
-
def add(file)
|
13
|
-
DOTFILES.add(file)
|
14
|
-
end
|
15
|
-
|
16
|
-
desc "remove <file>", "Download objects and refs from another repository"
|
17
|
-
def remove(file)
|
18
|
-
DOTFILES.remove(file)
|
19
|
-
end
|
20
|
-
|
21
|
-
desc "apply", "Copies all dotfiles defined in the user config to the system"
|
22
|
-
def apply
|
23
|
-
DOTFILES.apply
|
24
|
-
end
|
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
|
30
|
-
end
|