zae 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7107716877c5697e0ad9e7d25ee266a8e22b8c6914b580398bbcca712c1a3f70
4
+ data.tar.gz: fea4655d21aaf270a3a554f436ef430bb7d8f2121cc4412e5e03e53632365c64
5
+ SHA512:
6
+ metadata.gz: ca8aa654b9a5e689640b1e5c14f919f6c12b6b8f7728516cc5bd8daba75f8a6a0b0372be967556dc76abf6b56717f248b4dac5bac5af4c207ef000f2e3937c2c
7
+ data.tar.gz: b6002c33b403a78322abf47c57b30785b15ef2c6d9b3fbbfef92fec44cfb94518add7e506545c65530f088f955dbcc125e05953e638988732fa80990b95945bd
data/exe/zae ADDED
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/zae'
4
+
5
+ require 'gli'
6
+
7
+ # Cli main parser
8
+ class Cli
9
+ extend GLI::App
10
+
11
+ # cli options
12
+ subcommand_option_handling :normal
13
+ arguments :strict
14
+
15
+ # information
16
+ program_desc 'a handy runner of distributions packages manager commands. '
17
+ version Zae::VERSION
18
+
19
+ # commands base
20
+ COMMANDS = Zae::Commands.new
21
+
22
+ desc 'install package(s) from repositories'
23
+ arg_name 'package(s) name'
24
+ command :install do |c|
25
+ c.arg 'arguments'
26
+ c.action do |_, _, args|
27
+ p COMMANDS.install args
28
+ end
29
+ end
30
+
31
+ desc 'remove one or more installed packages'
32
+ arg_name 'package(s) name'
33
+ command :remove do |c|
34
+ c.action do |_, _, args|
35
+ COMMANDS.remove args
36
+ end
37
+ end
38
+
39
+ desc 'search for matching packages of term'
40
+ arg_name 'package name'
41
+ command :search do |c|
42
+ c.action do |_, _, args|
43
+ COMMANDS.search args
44
+ end
45
+ end
46
+
47
+ desc 'update database'
48
+ arg_name ''
49
+ command :update do |c|
50
+ c.action do
51
+ COMMANDS.update
52
+ end
53
+ end
54
+
55
+ desc 'upgrade packages'
56
+ arg_name ''
57
+ command :upgrade do |c|
58
+ c.arg 'arguments'
59
+ c.action do
60
+ COMMANDS.upgrade
61
+ end
62
+ end
63
+
64
+ desc 'auto remove system residual packages dependencies'
65
+ arg_name ''
66
+ command :autoremove do |c|
67
+ c.action do |_, _, args|
68
+ COMMANDS.autoremove args
69
+ end
70
+ end
71
+
72
+ desc 'download package binary'
73
+ arg_name 'package name'
74
+ command :download do |c|
75
+ c.action do |_, _, args|
76
+ COMMANDS.download args
77
+ end
78
+ end
79
+
80
+ desc 'list installed packages'
81
+ arg_name ''
82
+ command :installed do |c|
83
+ c.action do |_, _, args|
84
+ COMMANDS.installed args
85
+ end
86
+ end
87
+
88
+ desc 'view info about a specific package'
89
+ arg_name 'package name'
90
+ command :info do |c|
91
+ c.action do |_, _, args|
92
+ COMMANDS.info args
93
+ end
94
+ end
95
+
96
+ desc 'fix system package manager issues'
97
+ arg_name 'packages'
98
+ command :fix do |c|
99
+ c.action do |_, _, args|
100
+ COMMANDS.fix args
101
+ end
102
+ end
103
+
104
+ desc 'package manager version'
105
+ arg_name ''
106
+ command :fix do |c|
107
+ c.action do
108
+ COMMANDS.version
109
+ end
110
+ end
111
+ end
112
+
113
+ exit Cli.run(ARGV)
data/lib/zae/become.rb ADDED
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module Zae
6
+ # define how command should be run, either to become super user or not.
7
+ class Become
8
+ attr_accessor
9
+
10
+ SUDO_PATH = Pathname.new('/usr/bin/sudo')
11
+ DOAS_PATH = Pathname.new('/usr/bin/doas')
12
+
13
+ def initialize(action, config)
14
+ @action = action
15
+ @config = config
16
+ end
17
+
18
+ def need?
19
+ return false if @config[:become].nil?
20
+
21
+ if @config[:become].key?(@action)
22
+ true
23
+ else
24
+ false
25
+ end
26
+ end
27
+
28
+ # query which become methods are available on user system
29
+ def exec
30
+ if SUDO_PATH.exist?
31
+ SUDO_PATH
32
+ elsif DOAS_PATH.exist?
33
+ DOAS_PATH
34
+ else
35
+ 'unknown'
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zae
4
+ # Feature requirement:
5
+ class Commands
6
+ # update repository database
7
+ def update
8
+ exec :update
9
+ end
10
+
11
+ # upgrade system package(s)
12
+ def upgrade
13
+ exec :upgrade
14
+ end
15
+
16
+ def deps
17
+ exec :deps
18
+ end
19
+
20
+ def autoremove(...)
21
+ exec(:autoremove, ...)
22
+ end
23
+
24
+ def depends
25
+ exec :depends
26
+ end
27
+
28
+ def install(...)
29
+ exec(:install, ...)
30
+ end
31
+
32
+ def installed(...)
33
+ exec(:installed, ...)
34
+ end
35
+
36
+ def remove(...)
37
+ exec(:remove, ...)
38
+ end
39
+
40
+ def download(...)
41
+ exec(:download, ...)
42
+ end
43
+
44
+ def fix(...)
45
+ exec(:fix, ...)
46
+ end
47
+
48
+ # search for given package
49
+ def search(...)
50
+ exec(:search, ...)
51
+ end
52
+
53
+ # provide user with manual information
54
+ def help
55
+ exec :help
56
+ end
57
+
58
+ # show package information
59
+ def show
60
+ exec :show
61
+ end
62
+
63
+ def info(...)
64
+ exec(:info, ...)
65
+ end
66
+
67
+ # packager current version
68
+ def version
69
+ exec :version
70
+ end
71
+
72
+ private
73
+
74
+ def exec(...)
75
+ print_run = lambda { |cmd|
76
+ puts "command: #{cmd}"
77
+ system cmd
78
+ }
79
+
80
+ Translate.new(...)
81
+ .to_str
82
+ .yield_self(&print_run)
83
+ end
84
+ end
85
+ end
data/lib/zae/config.rb ADDED
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module Zae
6
+ # Query for configuration files and returns matching ones
7
+ class Config
8
+ CFG_FOLDER = Pathname.new(File.join(Dir.home, '.config', 'zae'))
9
+
10
+ # package manager found
11
+ attr_accessor :found
12
+
13
+ def initialize
14
+ @found = discovered || files[executable]
15
+ end
16
+
17
+ # config files folder location
18
+ def folder
19
+ xdg_config_folder || CFG_FOLDER
20
+ end
21
+
22
+ # package manager executable location
23
+ def executable
24
+ return Pathname.new(discovered[:exec]).basename.to_path.to_sym if discovered?
25
+
26
+ # get all availables executables
27
+ exec = files.each_value.find { |cfg| Config.executable? cfg[:exec] }[:exec]
28
+ Pathname.new(exec).basename.to_path.to_sym
29
+ end
30
+
31
+ # active package manager executable
32
+ alias active executable
33
+
34
+ # once executable is discovered create a new file w/ its path or name in
35
+ # $HOME so to avoid probing for it in every startup
36
+ def discovered
37
+ exec = folder.join('.discovered').read.chop.to_sym if discovered?
38
+
39
+ files[exec] || nil
40
+ end
41
+
42
+ # is there any configuration available?
43
+ def any?
44
+ files.any?
45
+ # - config folder do exist?
46
+ # - any yaml config file?
47
+ # - .discovered do exist?
48
+ end
49
+
50
+ private
51
+
52
+ # executable exist?
53
+ def self.executable?(exec)
54
+ File.executable? exec.to_s
55
+ end
56
+
57
+ # Get all Configuration files
58
+ def files
59
+ # return if any?
60
+
61
+ {}.tap do |elem|
62
+ folder.each_child do |file|
63
+ name = file.sub_ext('').basename.to_s.to_sym
64
+ elem[name] = load_config(file)
65
+ end
66
+ end
67
+ end
68
+
69
+ # once executable is discovered create a new file w/ its path or name in
70
+ # $HOME to avoid probing everytime run
71
+ def discovered?
72
+ folder.join('.discovered').exist?
73
+ end
74
+
75
+ # when xdg config is set, defaults to it to probe for configuration fiels
76
+ def xdg_config_folder
77
+ Pathname.new(File.join(ENV['XDG_CONFIG_HOME'], 'zae')) if ENV['XDG_CONFIG_HOME']
78
+ end
79
+
80
+ # Load file with famous serialization formats
81
+ def load_config(file)
82
+ require 'yaml'
83
+ YAML.load_file(file, symbolize_names: true)
84
+ end
85
+ end
86
+ end
data/lib/zae/engage.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zae
4
+ # make it so
5
+ class Engage
6
+ def commands
7
+ Commands.new
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zae
4
+ # translate action to final command
5
+ class Translate
6
+ def initialize(action, args = [], config = Config.new.found,
7
+ become: Become.new(action, config))
8
+ @args = args
9
+ @action = action
10
+
11
+ @config = config
12
+ @become = become
13
+ end
14
+
15
+ def to_str
16
+ cmd = @become.need? ? @config[:become][@action] : @config[:user][@action]
17
+ command cmd
18
+ end
19
+
20
+ private
21
+
22
+ # TODO: raise 'command was not provided' and return if command.nil?
23
+ # query for final command composition
24
+ def command(action)
25
+ executable = @config[:exec]
26
+
27
+ [].tap do |el|
28
+ el << @become.exec if @become.need?
29
+ el << executable
30
+ el << action
31
+ end
32
+ .+(@args)
33
+ .join(' ')
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zae
4
+ VERSION = '0.8.3'
5
+ end
data/lib/zae.rb ADDED
@@ -0,0 +1,10 @@
1
+ require_relative 'zae/become'
2
+ require_relative 'zae/commands'
3
+ require_relative 'zae/config'
4
+ require_relative 'zae/translate'
5
+ require_relative 'zae/version'
6
+
7
+ # a handy runner of distributions packages manager commands.
8
+ module Zae
9
+ class Error < StandardError; end
10
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zae
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.3
5
+ platform: ruby
6
+ authors:
7
+ - easbarba
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-05-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '13.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 13.0.6
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '13.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 13.0.6
33
+ - !ruby/object:Gem::Dependency
34
+ name: reek
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 6.1.1
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 6.1.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.11'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.11'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rufo
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.13.0
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.13.0
75
+ - !ruby/object:Gem::Dependency
76
+ name: gli
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.21'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '2.21'
89
+ description:
90
+ email:
91
+ executables:
92
+ - zae
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - exe/zae
97
+ - lib/zae.rb
98
+ - lib/zae/become.rb
99
+ - lib/zae/commands.rb
100
+ - lib/zae/config.rb
101
+ - lib/zae/engage.rb
102
+ - lib/zae/translate.rb
103
+ - lib/zae/version.rb
104
+ homepage: https://github.com/easbarba/zae
105
+ licenses:
106
+ - gpl-v3
107
+ metadata:
108
+ homepage_uri: https://github.com/easbarba/zae
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '2.7'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubygems_version: 3.3.5
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: a handy runner of distributions packages manager commands
128
+ test_files: []