cmt 0.0.4 → 0.0.6

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: 1229896c4197b67c41c64fe2c898e620adfe16c3b7f1ce73c49895ad4932df2c
4
- data.tar.gz: 1ed6a854c9fc5327e3886dd0146aaa25d3865e8ce340532a9fd499faa6a74fe0
3
+ metadata.gz: 4df6c8d43f4b993e82bbf050c270c7d891e949f31f5c7e68ea2eeb4eb5703b8a
4
+ data.tar.gz: cebf41863388b9dc98cc4b6f60a1c3fc097e61c26d52b073f44be5e368ec1013
5
5
  SHA512:
6
- metadata.gz: c59e660257922f1249819a2ba04c67ca0c59d4333170745437cdd404e83ee088f75823dbc0422d2b901a085fc23a3d007c3a2bc57cacde642c30f3ed8cbe7fc1
7
- data.tar.gz: d8c503eb326f7c57c302fca0565b78fe0e46203b4a295fe31a6cd2bfd770ac7534a8d0f26c47f6a4ea7f9f34f7521bf9df6593872d5e9fe7e525ff6609abcef9
6
+ metadata.gz: dafe415e6f6af6928593482ac77f41c6b3de7c4f8354e6492f0aee1bb6a1fd27d2f7fdad7c6c56dbcac45fff132646f1f6203207c130574102de574f4b111c12
7
+ data.tar.gz: 3630fcfeaba1c8f8d7a28478a185ffddcd059c4d75b4b155d669aa428d66efb278421716ab9f2bb15c523e803c7451346910a49b7e8fea0a6e66529b84665c96
data/lib/cmt.rb CHANGED
@@ -1,31 +1,42 @@
1
- require "thor"
2
- require "pathname"
3
- require "fileutils"
4
- require "json"
5
- require "logger"
6
-
7
- require_relative "config/git_config"
8
- require_relative "dotfiles/dotfiles_cli"
9
- require_relative "pkg/pkg"
10
- require_relative "version"
11
-
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
16
- end
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::CONFIG_DIR
19
+ if force
20
+ FileUtils.rm_rf(Config::CONFIG_DIR)
21
+ else
22
+ Log::LOGGER.error("Config already exists at '#{Config::CONFIG_DIR}'")
23
+ abort("Config already exists at '#{Config::CONFIG_DIR}'")
24
+ end
25
+ end
26
+
27
+ `git clone #{repo} #{Config::CONFIG_DIR}`
28
+ end
17
29
 
18
- class Cmt < Thor
19
- desc "config SUBCOMMAND ...ARGS", "manage set of tracked repositories"
20
- subcommand "config", GitConfig
30
+ desc 'config SUBCOMMAND ...ARGS', 'manage set of tracked repositories'
31
+ subcommand 'config', GitConfig
21
32
 
22
- desc "dotfiles SUBCOMMAND ...ARGS", "manage set of tracked repositories"
23
- subcommand "dotfiles", DotfilesCli
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 "version", "Print version"
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,19 @@
1
- require "thor"
2
- require "fileutils"
1
+ require 'thor'
2
+ require 'fileutils'
3
+ require 'json'
3
4
 
4
- $CONFIG_DIR = File.join(Dir.home, ".config", "cmt")
5
+ module Config
6
+ CONFIG_DIR = File.join(Dir.home, '.config', 'cmt').freeze
5
7
 
6
- class Config
7
8
  def self.get_config_json(file, default_config)
8
9
  FileUtils.mkdir_p File.dirname(file)
9
- File.write(file, JSON.pretty_generate(default_config, { indent: " " })) unless File.exist?(file)
10
+ File.write(file, JSON.pretty_generate(default_config, { indent: ' ' })) unless File.exist?(file)
10
11
 
11
12
  config = JSON.load_file(file)
12
13
  default_config.merge(config)
13
14
  end
14
15
 
15
16
  def self.write_config_file(file, config)
16
- File.write(file, JSON.pretty_generate(config, { indent: " " }))
17
+ File.write(file, JSON.pretty_generate(config, { indent: ' ' }))
17
18
  end
18
19
  end
@@ -1,38 +1,39 @@
1
- require "thor"
1
+ require 'thor'
2
2
 
3
- require_relative "config"
3
+ require_relative 'config'
4
+ require_relative '../util/log'
4
5
 
5
6
  class GitConfig < Thor
6
- desc "init", "Init"
7
+ desc 'init', 'Init'
7
8
  option :force, type: :boolean, default: false
8
9
  def init(repo)
9
- force = options["force"]
10
+ force = options['force']
10
11
 
11
- if File.exist? $CONFIG_DIR
12
+ if File.exist? Config::CONFIG_DIR
12
13
  if force
13
- FileUtils.rm_rf($CONFIG_DIR)
14
+ FileUtils.rm_rf(Config::CONFIG_DIR)
14
15
  else
15
- $logger.error("Config already exists at '#{$CONFIG_DIR}'")
16
- abort("Config already exists at '#{$CONFIG_DIR}'")
16
+ Log::LOGGER.error("Config already exists at '#{Config::CONFIG_DIR}'")
17
+ abort("Config already exists at '#{Config::CONFIG_DIR}'")
17
18
  end
18
19
  end
19
20
 
20
- `git clone #{repo} #{$CONFIG_DIR}`
21
+ `git clone #{repo} #{Config::CONFIG_DIR}`
21
22
  end
22
23
 
23
- desc "update", "update"
24
- option :message, default: "Update config"
24
+ desc 'update', 'update'
25
+ option :message, default: 'Update config'
25
26
  def update
26
27
  message = options['message']
27
- Dir.chdir($CONFIG_DIR) do
28
+ Dir.chdir(Config::CONFIG_DIR) do
28
29
  changes = `git status --porcelain=v1`
29
30
  num_changes = changes.split.length
30
31
 
31
32
  if num_changes.zero?
32
- $logger.error("No changes to commit in '#{$CONFIG_DIR}'")
33
- abort("No changes to commit in '#{$CONFIG_DIR}'")
33
+ Log::LOGGER.error("No changes to commit in '#{Config::CONFIG_DIR}'")
34
+ abort("No changes to commit in '#{Config::CONFIG_DIR}'")
34
35
  else
35
- $logger.info("Commit changes")
36
+ Log::LOGGER.info('Commit changes')
36
37
  system 'git', 'add', '.'
37
38
  system 'git', 'commit', '-m', "'#{message}'"
38
39
  system 'git', 'push'
@@ -40,31 +41,31 @@ class GitConfig < Thor
40
41
  end
41
42
  end
42
43
 
43
- desc "status", "Show git status in '#{$CONFIG_DIR}'"
44
+ desc 'status', "Show git status in '#{Config::CONFIG_DIR}'"
44
45
  def status(*args)
45
- Dir.chdir($CONFIG_DIR) do
46
+ Dir.chdir(Config::CONFIG_DIR) do
46
47
  system 'git', 'status', *args
47
48
  end
48
49
  end
49
50
 
50
- desc "pull", "Pull newest changes in '#{$CONFIG_DIR}'"
51
+ desc 'pull', "Pull newest changes in '#{Config::CONFIG_DIR}'"
51
52
  def pull(*args)
52
- Dir.chdir($CONFIG_DIR) do
53
+ Dir.chdir(Config::CONFIG_DIR) do
53
54
  system 'git', 'pull', *args
54
55
  end
55
56
  end
56
57
 
57
- desc "exec", "Execute any git command in '#{$CONFIG_DIR}'"
58
+ desc 'exec', "Execute any git command in '#{Config::CONFIG_DIR}'"
58
59
  def exec(*args)
59
- Dir.chdir($CONFIG_DIR) do
60
+ Dir.chdir(Config::CONFIG_DIR) do
60
61
  system 'git', *args
61
62
  end
62
63
  end
63
64
 
64
- desc "code", "Open '#{$CONFIG_DIR}' in code"
65
+ desc 'code', "Open '#{Config::CONFIG_DIR}' in code"
65
66
  def code(*args)
66
- $logger.info("Open '#{$CONFIG_DIR}' in code")
67
- Dir.chdir($CONFIG_DIR) do
67
+ Log::LOGGER.info("Open '#{Config::CONFIG_DIR}' in code")
68
+ Dir.chdir(Config::CONFIG_DIR) do
68
69
  system 'code', '.', *args
69
70
  end
70
71
  end
@@ -1,22 +1,23 @@
1
- require "thor"
1
+ require 'thor'
2
2
  require 'pathname'
3
3
  require 'fileutils'
4
4
  require 'json'
5
- require "logger"
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 Dotfiles
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
11
+ class Env
12
+ CONFIG_SUB_DIR = 'env'.freeze
13
+ ROOT_PATH = File.join(Config::CONFIG_DIR, CONFIG_SUB_DIR).freeze
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
- "files" => [],
19
- "folders" => []
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
- $logger.info("Added '#{parsed_file}'")
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
- $logger.info("Removed '#{local_file}'")
70
+ Log::LOGGER.info("Removed '#{local_file}'")
70
71
  end
71
72
 
72
73
  def apply
73
- $logger.info('Start apply')
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
- $logger.debug("Copy #{abs_file} to #{dest_file}")
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
- $logger.debug("Copy #{abs_file} to #{dest_file}")
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
- $logger.info('Finished apply')
99
+ Log::LOGGER.info('Finished apply')
99
100
  end
100
101
 
101
102
  def sync
102
- $logger.info('Start sync')
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
- $logger.debug("Copy #{dest_file} to #{abs_file}")
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
- $logger.debug("Copy #{dest_file} to #{abs_file}")
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
- $logger.info('Finished sync')
128
+ Log::LOGGER.info('Finished sync')
128
129
  end
129
130
 
130
131
  def get_local_path(file)
@@ -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,84 @@
1
- require "thor"
1
+ require 'thor'
2
2
 
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"
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
+ require_relative '../util/log'
10
11
 
11
12
  class Pkg < Thor
12
13
  SYSTEM_PACKAGE_MANGER = {
13
- "manjaro" => Pacman,
14
- "fedora" => Dnf,
15
- "windows" => Winget
14
+ 'manjaro' => 'pacman',
15
+ 'fedora' => 'dnf',
16
+ 'windows' => 'winget'
16
17
  }.freeze
17
- OTHER_PACKAGE_MANGER = {
18
- "pip" => Pip,
19
- "snap" => Snap,
20
- "yay" => Yay
18
+ PACKAGE_MANGER = {
19
+ 'pacman' => Pacman,
20
+ 'dnf' => Dnf,
21
+ 'winget' => Winget,
22
+ 'pip' => Pip,
23
+ 'snap' => Snap,
24
+ 'yay' => Yay
21
25
  }.freeze
22
- RELEASE_FILE = "/etc/os-release".freeze
26
+ RELEASE_FILE = '/etc/os-release'.freeze
23
27
 
24
- desc "install_all", "Install"
25
- option "pkgm", default: "system"
26
- def install_all(*args)
27
- manager = get_package_manager(options["pkgm"])
28
+ # desc "install_all", "Install"
29
+ # option "pkgm", default: "system"
30
+ # def install_all(*args)
31
+ # manager = Pkg.get_package_manager(options["pkgm"])
28
32
 
29
- config_file = PkgConfig.get_config_file(manager)
30
- config = Config.get_config_json(config_file, PkgConfig.default_config)
33
+ # config_file = PkgConfig.get_config_file(manager)
34
+ # config = Config.get_config_json(config_file, PkgConfig.default_config)
31
35
 
32
- packages = config["packages"]
36
+ # packages = config["packages"]
33
37
 
34
- manager.install_all(packages, *args)
35
- end
38
+ # manager.install_all(packages, *args)
39
+ # end
36
40
 
37
- desc "install", "Install"
38
- option "pkgm", default: "system"
39
- def install(package, *args)
40
- manager = get_package_manager(options["pkgm"])
41
+ def self.get_package_manager(pkgm)
42
+ pkgm = Pkg.get_system_package_manager unless pkgm != 'system'
43
+ manager = PACKAGE_MANGER[pkgm]
41
44
 
42
- installed = manager.install(package, *args)
45
+ if manager.nil?
46
+ Log::LOGGER.error("'#{pkgm}' is not supported")
47
+ abort("'#{pkgm}' is not supported")
48
+ end
43
49
 
44
- return unless installed
50
+ Log::LOGGER.info("Using package manager '#{manager}'")
45
51
 
46
- PkgConfig.add(manager, package)
52
+ manager
47
53
  end
48
54
 
49
- desc "update", "update"
50
- option "pkgm", default: "system"
51
- def update(*args)
52
- manager = get_package_manager(options["pkgm"])
53
-
54
- manager.update(*args)
55
- end
55
+ def self.get_system_package_manager
56
+ manager = nil
56
57
 
57
- desc "uninstall", "uninstall"
58
- option "pkgm", default: "system"
59
- def uninstall(package, *args)
60
- manager = get_package_manager(options["pkgm"])
58
+ if Gem.win_platform?
59
+ manager = SYSTEM_PACKAGE_MANGER['windows']
60
+ else
61
+ r = { 'distro' => nil }
62
+ unless File.exist?(RELEASE_FILE)
63
+ Log::LOGGER.error("'#{RELEASE_FILE}' does not exist")
64
+ abort("'#{RELEASE_FILE}' does not exist")
65
+ end
61
66
 
62
- uninstalled = manager.uninstall(package, *args)
67
+ File.foreach(RELEASE_FILE) do |line|
68
+ r = { 'distro' => ::Regexp.last_match(1) } if line =~ /^ID=(.*)/
69
+ end
63
70
 
64
- return unless uninstalled
71
+ manager = SYSTEM_PACKAGE_MANGER[r['distro']]
72
+ end
65
73
 
66
- PkgConfig.remove(manager, package)
74
+ return manager
67
75
  end
68
76
 
69
- no_commands do
70
- def get_package_manager(pkgm)
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}'")
77
+ desc 'system SUBCOMMAND ...ARGS', 'manage system packages'
78
+ subcommand 'system', Pkg.get_package_manager('system')
100
79
 
101
- manager
102
- end
80
+ PACKAGE_MANGER.each do |key, value|
81
+ desc "#{key} SUBCOMMAND ...ARGS", "manage #{key} packages"
82
+ subcommand key, value
103
83
  end
104
84
  end
@@ -1,35 +1,57 @@
1
- require "json"
1
+ require 'json'
2
2
 
3
- require_relative "../config/config"
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 = "pkg".freeze
7
- ROOT_PATH = File.join($CONFIG_DIR, CONFIG_SUB_DIR).freeze
13
+ CONFIG_SUB_DIR = 'pkg'.freeze
14
+ ROOT_PATH = File.join(Config::CONFIG_DIR, CONFIG_SUB_DIR).freeze
8
15
  DEFAULT_CONFIG = {
9
- "repos" => [],
10
- "packages" => []
16
+ ConfigOptions::PACKAGES => [],
17
+ ConfigOptions::REMOTES => [],
18
+ ConfigOptions::REPOS => []
11
19
  }.freeze
12
20
 
13
- def self.add(pkgm, package)
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
- packages = config["packages"]
32
+ puts(config)
19
33
 
20
- packages.append package unless packages.include? package
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, package)
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
- packages = config["packages"]
31
-
32
- packages.delete package if packages.include? package
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
data/lib/pkg/pkgm/dnf.rb CHANGED
@@ -1,17 +1,50 @@
1
- class Dnf
2
- def self.install_all(packages, *args)
3
- system "sudo", "dnf", "install", *args, *packages
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
- def self.install(package, *args)
7
- system "sudo", "dnf", "install", *args, package
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
- def self.update(*args)
11
- system "sudo", "dnf", "update", *args
22
+ desc 'list_repos', 'List repos'
23
+ def list_repos
24
+ system 'dnf', 'repolist', 'enabled'
12
25
  end
13
26
 
14
- def self.uninstall(package, *args)
15
- system "sudo", "dnf", "remove", *args, package
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
@@ -1,17 +1,29 @@
1
- class Pacman
2
- def self.install_all(packages, *args)
3
- system "sudo", "pacman", "-Sy", *args, *packages
4
- end
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
- def self.install(package, *args)
7
- system "sudo", "pacman", "-Sy", *args, package
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
- def self.update(*args)
11
- system "sudo", "pacman", "-Syu", *args
18
+ desc 'update', 'update'
19
+ def update(*args)
20
+ system 'sudo', 'pacman', '-Syu', *args
12
21
  end
13
22
 
14
- def self.uninstall(package, *args)
15
- system "sudo", "pacman", "-R", *args, package
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
- class Pip
2
- def self.install_all(packages, *args)
3
- system "python3", "-m", "pip", "install", *args, *packages
4
- end
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
- def self.install(package, *args)
7
- system "python3", "-m", "pip", "install", *args, package
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
- def self.update(*_args)
11
- $logger.error("Update is not supported for pip")
12
- abort("Update is not supported for pip")
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
- def self.uninstall(package, *args)
16
- system "python3", "-m", "pip", "uninstall", *args, package
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
- class Snap
2
- def self.install_all(packages, *args)
3
- system "snap", "install", *args, *packages
4
- end
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
- def self.install(package, *args)
7
- system "snap", "install", *args, package
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
- def self.update(*_args)
11
- $logger.error("Update is not supported for snap")
12
- abort("Update is not supported for snap")
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
- def self.uninstall(package, *args)
16
- system "snap", "remove", *args, package
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
@@ -1,19 +1,31 @@
1
- class Winget
2
- def self.install_all(packages, *args)
3
- packages.each do |package|
4
- Winget.install(package, *args)
5
- end
6
- end
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
- def self.install(package, *args)
9
- system "winget", "install", *args, "--id=#{package}", "-e"
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
- def self.update(*_args)
13
- system "winget", "upgrade"
20
+ desc 'update', 'update'
21
+ def update(*_args)
22
+ system 'winget', 'upgrade'
14
23
  end
15
24
 
16
- def self.uninstall(package, *args)
17
- system "winget", "uninstall", *args, "--id=#{package}", "-e"
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
- class Yay
2
- def self.install_all(packages, *args)
3
- system "yay", "-Sy", *args, *packages
4
- end
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
- def self.install(package, *args)
7
- system "yay", "-Sy", *args, package
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
- def self.update(*args)
11
- system "yay", "-Syu", *args
18
+ desc 'update', 'update'
19
+ def update(*args)
20
+ system 'yay', '-Syu', *args
12
21
  end
13
22
 
14
- def self.uninstall(package, *args)
15
- system "yay", "-R", *args, package
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
@@ -1,12 +1,12 @@
1
- class FileUtil
2
- USER_HOME = "user-home".freeze
1
+ module FileUtil
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
@@ -1,3 +1,3 @@
1
1
  # module Cmt
2
- VERSION = "0.0.4".freeze
2
+ VERSION = '0.0.6'.freeze
3
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.4
4
+ version: 0.0.6
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-10 00:00:00.000000000 Z
11
+ date: 2023-07-12 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/dotfiles/dotfiles.rb
40
- - lib/dotfiles/dotfiles_cli.rb
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