helpema 3.2.210924 → 5.0.221213

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 958027b0a2546243bae724c0a543197d7632385c0f9049d8e59ed53349b18f4d
4
- data.tar.gz: d57d402890e736b580fc052c66308df90a6e29202d467cd4e26714ad11b64331
3
+ metadata.gz: 0cc846b64938fbe9205c778b91c05269f7c302b519c207245d06008b29d74b1a
4
+ data.tar.gz: 1c175a3dad5b9ae1d189d1b4fc85195095e5c721d3accd8c12ec63c2caa77508
5
5
  SHA512:
6
- metadata.gz: dd576603c81835d9610eac6d15487d25d82491eec8de717fcfbe6a16c51c865968d8ac259dddc45e02f2148f7653c6fa5b9ed5be55eb05c878b184df3bc5cdec
7
- data.tar.gz: 65f36c77c56ded75225ecd35fe6f6f4bb3581aeff1c3ce1de855f423e65de78e3e69d1131a63e7b18760b1224f27eda14a33c0a41e40e55bef67d8c0cb89b488
6
+ metadata.gz: 02a981918c3c2ec673c3079681cdf0a854e8eefaccd880962df20ede2189836b374630831defa5715156432b4f3db3ebbcace213ff7515c12873932f3383f593
7
+ data.tar.gz: 3e053f503707a61fe78e90cebdaf83011805eb1c3a8d7c0a619ff373e1b6a292e9edc82adfc169c6d937cfde93780952659444f9d1a3e86756f5a78dc9799df0
data/README.md CHANGED
@@ -1,14 +1,13 @@
1
1
  # Helpema
2
2
 
3
- * [VERSION 3.2.210924](https://github.com/carlosjhr64/helpema/releases)
3
+ * [VERSION 5.0.221213](https://github.com/carlosjhr64/helpema/releases)
4
4
  * [github](https://github.com/carlosjhr64/helpema)
5
5
  * [rubygems](https://rubygems.org/gems/helpema)
6
6
 
7
7
  ## DESCRIPTION:
8
8
 
9
- Meant to be an eclectic collection of useful single functions and wrappers.
10
-
11
- Featured method: `requires "good ~>3.0", "bad ~>2.7", "ugly ~>1.8"`
9
+ Meant to be an eclectic collection of useful Linux command wrappers.
10
+ Facilitates creation of custom wrappers for any Linux command.
12
11
 
13
12
  ## INSTALL:
14
13
 
@@ -18,76 +17,62 @@ $ gem install helpema
18
17
 
19
18
  ## SYNOPSIS:
20
19
 
21
- ### requires
20
+ Note that `Helpema` auto-loads assets as requested.
22
21
  ```ruby
23
22
  require 'helpema'
24
23
  include Helpema
25
- using Helpema
26
-
27
- ### requires ###
28
- # Ensure ruby's and helpema's version.
29
- # Returns the list of loaded gems.
30
- # For those quick little scripts one writes in one's bin
31
- # that annoyingly keep falling out of maintainance... right?
32
- requires'
33
- ruby ~>3.0
34
- helpema ~>3.1
35
- base_convert ~>4.0
36
- entropia ~>0.1'
37
- #=> ["base_convert", "entropia"]
38
24
  ```
39
- ### String#satisfies?
25
+ ### Helpema::Piper
40
26
  ```ruby
41
- ### String#satisfies? ###
42
- # Uses Gem::Requirement and Gem::Version to check version strings.
43
- '1.2.3'.satisfies? '~>1.1' #=> true
44
- '1.2.3'.satisfies? '~>1.3' #=> false
27
+ # These will raise RuntimeError unless version matches:
28
+ Piper.validate_command('ruby', '^ruby 3.1.2p20', '--version')
29
+ Piper.validate_command('ssss-split', 'Version: 0\.[567]$', '-v')
30
+ # Piper.run_command(cmd, options={}, script:nil, usage=nil, synonyms:nil,
31
+ # mode:'r', exception:nil, forward_pass:nil **popt, &blk)
32
+ # Too many features to fully cover in a synopsis...
33
+ Piper.run_command('date',{d: 'Dec 31, 2020',I: true}) #=> "2020-12-31\n"
34
+ Piper.run_command('bash',script:'echo "Hello"',mode:'w+') #=> "Hello\n"
35
+ Piper.run_command('fish',script:'false',mode:'w',exception:false) #=> false
36
+ begin
37
+ Piper.run_command('fish',script:'false',mode:'w',exception:'Ooops!')
38
+ rescue
39
+ msg = $!.message
40
+ end
41
+ msg #=> "Ooops!"
45
42
  ```
46
- ### run_command
43
+ ### Helpema::Piper::Refinements
47
44
  ```ruby
48
- ### run_command ###
49
- # Automates pipe creation to a system command.
50
- # See the code for all available features.
51
- run_command('date',{d: 'Dec 31, 2020'}) #=> "Thu Dec 31 12:00:00 AM PST 2020\n"
45
+ using Piper::Refinements
46
+ {d: 'Dec 31, 2020',I: true}.to_args #=> ["-d", "Dec 31, 2020", "-I"]
47
+ {'date=': '2022-12-10', wut: true}.to_args #=> ["--date=2022-12-10", "--wut"]
52
48
  ```
53
- ### define_command
49
+ ### extend Helpema::Piper
54
50
  ```ruby
55
51
  ### define_command ###
56
- # Creates a method out of a system command.
57
- # See the code for all available features.
58
- define_command(:date, cmd: 'date', usage: {d: nil}, synonyms: {string: :d})
59
- date(string: 'Dec 31, 2020') #=> "Thu Dec 31 12:00:00 AM PST 2020\n"
60
- ```
61
- ### to_arg
62
- ```ruby
63
- ### to_arg ###
64
- # A helper function to do system command calls.
65
- to_arg :q, true #=> "-q"
66
- to_arg :quiet, true #=> "--quiet"
67
- to_arg :verbose, false #=> nil
68
- to_arg :f, '/path-to/file' #=> ["-f", "/path-to/file"]
69
- to_arg :geo=, '10x20' #=> "--geo=10x20"
70
- to_arg :arg0, 'Hello World' #=> "Hello World"
52
+ # Create a method out of a system command.
53
+ module System
54
+ extend Helpema::Piper
55
+ define_command(:date, cmd: 'date', usage: {d: nil, I: true}, synonyms: {string: :d})
56
+ extend self
57
+ end
58
+ System.date(string: 'Dec 31, 2020') #=> "2020-12-31\n"
71
59
  ```
72
- ### Hash#to_args
60
+ ### Helpema::Rubish
73
61
  ```ruby
74
- ### Hash#to_args ###
75
- { q: true,
76
- quiet: true,
77
- verbose: false,
78
- f: '/path-to/file',
79
- :geo= => '10x20',
80
- arg0: 'Hello World' }.to_args
81
- #=> ["-q", "--quiet", "-f", "/path-to/file", "--geo=10x20", "Hello World"]
62
+ # Predefined Rubish:
63
+ Rubish.bash 'echo "Hello!"' #=> "Hello!\n"
64
+ Rubish.bash? 'which ruby' #=> true
65
+ Rubish.fish? 'false' #=> false
66
+ # Define you own Rubish shell call:
67
+ Rubish.shell('ruby', default:'puts RUBY_VERSION')
68
+ Rubish.ruby #=> "3.1.2\n"
69
+ Rubish.ruby('puts "Hello!"') #=> "Hello!\n"
70
+ # And define you own Rubish command call:
71
+ Rubish.command('which', usage:{arg0:nil})
72
+ def which(cmd) = Rubish.which(arg0:cmd)
73
+ which 'echo' # "/usr/bin/echo\n"
82
74
  ```
83
- ### Array#classify
84
- ```ruby
85
- ### Array#classify ###
86
- # Groups items in Array by class.
87
- [1, 2.0, :Three, 'Four', /Five/, :Six, 'Seven'].classify
88
- #=> {Integer=>[1], Float=>[2.0], Symbol=>[:Three, :Six], String=>["Four", "Seven"], Regexp=>[/Five/]}
89
- ```
90
- ### SSSS.split
75
+ ### Helpema::SSSS.split
91
76
  ```ruby
92
77
  ### SSSS.split ####
93
78
  SSSS.split(secret: "Top Secret!", threshold: 2, shares: 3)
@@ -107,7 +92,7 @@ SSSS.combine(secrets: ["3-055562917c41e68c6ab2c8", "1-27bf3cbfe8d2c25c7e8928"],
107
92
  ### YouTubeDL.json ###
108
93
  list = []
109
94
  url = 'https://www.youtube.com/watch?v=u4oK3ZSccZI'
110
- YouTubeDL.json(url){|json| list.push json}
95
+ Helpema::YouTubeDL.json(url){|json| list.push json}
111
96
  # The url was for just one video
112
97
  list.length #=> 1
113
98
  json = list[0]
@@ -119,7 +104,7 @@ json['title'] #=> "Fortnite Easy Last Ten"
119
104
  ```ruby
120
105
  ### ZBar.screen ###
121
106
  # Reads qrcodes on screen.
122
- string_or_nil = ZBar.screen
107
+ string_or_nil = Helpema::ZBar.screen
123
108
  ```
124
109
  ### ZBar.cam
125
110
  ```ruby
@@ -132,8 +117,8 @@ string_or_nil = ZBar.screen
132
117
  ```ruby
133
118
  ### GPG Symmetric ###
134
119
  ## String to String
135
- encrypted = GPG.encrypt(passphrase: '<Secret>', string: '<Plain Text>')
136
- decrypted = GPG.decrypt(passphrase: '<Secret>', string: encrypted)
120
+ encrypted = Helpema::GPG.encrypt(passphrase: '<Secret>', string: '<Plain Text>')
121
+ decrypted = Helpema::GPG.decrypt(passphrase: '<Secret>', string: encrypted)
137
122
  #=> "<Plain Text>"
138
123
  ## File to File
139
124
  # Got a text file...
@@ -142,9 +127,9 @@ decrypted = GPG.decrypt(passphrase: '<Secret>', string: encrypted)
142
127
  File.exist?(_='tmp/text.enc') and File.unlink(_)
143
128
  File.exist?(_='tmp/text.dec') and File.unlink(_)
144
129
  # Encrypt text file...
145
- GPG.encrypt(passphrase: '<Secret>', input: 'tmp/text.txt', output: 'tmp/text.enc') #=> ""
130
+ Helpema::GPG.encrypt(passphrase: '<Secret>', input: 'tmp/text.txt', output: 'tmp/text.enc') #=> ""
146
131
  # Decrypt encrypted file...
147
- GPG.decrypt(passphrase: '<Secret>', input: 'tmp/text.enc', output: 'tmp/text.dec') #=> ""
132
+ Helpema::GPG.decrypt(passphrase: '<Secret>', input: 'tmp/text.enc', output: 'tmp/text.dec') #=> ""
148
133
  # Decrypted file should match...
149
134
  `md5sum tmp/text.dec` #~> ^d27b3111fdeb72f2862909c216214bc1
150
135
  ## IO to IO
@@ -152,25 +137,20 @@ require 'stringio'
152
137
  pio = StringIO.new '<Plain>'
153
138
  eio = StringIO.new ''
154
139
  dio = StringIO.new ''
155
- GPG.encrypt(passphrase: '<Secret>', ioin: pio, ioout: eio)
140
+ Helpema::GPG.encrypt(passphrase: '<Secret>', ioin: pio, ioout: eio)
156
141
  eio.rewind
157
- GPG.decrypt(passphrase: '<Secret>', ioin: eio, ioout: dio)
142
+ Helpema::GPG.decrypt(passphrase: '<Secret>', ioin: eio, ioout: dio)
158
143
  dio.string #=> "<Plain>"
159
144
  ```
160
-
161
145
  ## TROUBLESHOOTING:
162
146
 
163
- Command version mismatch
164
- : set `Helpema::WRAPPER.version = "your.version"` or just nil it.
165
-
166
- More documentation
167
- : see [sig/helpema.rb](sig/helpema.rbs) for the expected method signatures.
147
+ + Command version mismatch: set `Helpema::WRAPPER.version = "your.version"` or just nil it.
168
148
 
169
149
  ## LICENSE:
170
150
 
171
151
  (The MIT License)
172
152
 
173
- Copyright (c) 2021 CarlosJHR64
153
+ Copyright (c) 2022 CarlosJHR64
174
154
 
175
155
  Permission is hereby granted, free of charge, to any person obtaining
176
156
  a copy of this software and associated documentation files (the
@@ -1,6 +1,6 @@
1
1
  module Helpema
2
2
  module FFMPEG
3
- extend Helpema
3
+ extend Piper
4
4
 
5
5
  FFMPEG.define_command(:_hash,
6
6
  cmd: 'ffmpeg',
data/lib/helpema/gpg.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  module Helpema
2
2
  module GPG
3
- extend Helpema
3
+ extend Piper
4
4
  class << self; attr_accessor :version; end
5
- GPG.version = '^gpg \\(GnuPG\\) 2\.[234]\.' # version as of this writing is 2.2.27
5
+ # version as of this writing is 2.2.27
6
+ GPG.version = '^gpg \\(GnuPG\\) 2\.[234]\.'
6
7
 
7
8
  GPG.define_command(:cryptor,
8
9
  cmd: 'gpg', version: GPG.version,
@@ -0,0 +1,104 @@
1
+ module Helpema
2
+ module Piper
3
+ module Refinements
4
+ refine ::Hash do
5
+ def to_args(usage:nil, synonyms:nil)
6
+ # create separate args from self with the translated synonyms
7
+ args = self.transform_keys(synonyms.to_h)
8
+ # pad usage's defaults to args
9
+ usage&.each{|key,default| args[key]=default unless args.has_key? key}
10
+ # order might be important so enforce usage
11
+ args = usage&.map{|k,v|[k,args[k]]} || args.to_a
12
+ # convert key,value tuples to final list of args
13
+ args.map!(&:to_arg)
14
+ # get rid of nil
15
+ args.compact!
16
+ # ...and finally flatten!
17
+ args.flatten!
18
+ return args
19
+ end
20
+ end
21
+ refine ::Symbol do
22
+ def to_flag
23
+ return nil if self[-1].match?(/\d/) # like :arg0
24
+ (self.length > 1)? "--#{self}": "-#{self}" # like --verbose or -V
25
+ end
26
+ end
27
+ refine ::Array do
28
+ def to_arg
29
+ Piper.to_arg(*self)
30
+ end
31
+ end
32
+ end
33
+
34
+ def Piper.validate_command(cmd, version, flag='--version')
35
+ raise "`#{cmd} #{flag}` !~ #{version}" unless
36
+ `#{cmd} #{flag}`.strip.match?(version)
37
+ end
38
+
39
+ # Note: popt is IO.popen's options(think of it as "pipe's options").
40
+ def define_command(name,
41
+ cmd:name.to_s.chomp('?').chomp('!'),
42
+ version:nil, v:nil,
43
+ usage:nil, synonyms:nil,
44
+ mode:'r', exception:nil, default:nil,
45
+ **popt, &forward_pass)
46
+ raise "bad name or cmd" unless name=~/^\w+[?!]?$/ and cmd=~/^[\w.\-]+$/
47
+ Piper.validate_command(cmd, version) if version
48
+ Piper.validate_command(cmd, v, '-v') if v
49
+ define_method(name) do |script=default, **options, &blk|
50
+ if mode[0]=='w'
51
+ raise 'need script to write' unless script or blk or forward_pass
52
+ else
53
+ raise 'cannot write script' if script
54
+ end
55
+ Piper.run_command(cmd, options, script:script,
56
+ usage:usage, synonyms:synonyms, mode:mode,
57
+ exception:exception, forward_pass:forward_pass, **popt, &blk)
58
+ end
59
+ end
60
+
61
+ using Refinements
62
+
63
+ def Piper.to_arg(key,value)
64
+ # keep only keys with value(no false or nil)
65
+ return nil unless value
66
+ # assume nil0/--long/-short
67
+ key = key.to_flag
68
+ if key
69
+ return key if value==true # a flag
70
+ return "#{key}#{value}" if key[-1]=='=' # joined key=value
71
+ return [key,value.to_s]
72
+ end
73
+ # It's a Nth arg, like arg0...
74
+ return value.to_s
75
+ end
76
+
77
+ # Assume caller knows what it's doing(no dummy proofing here)
78
+ def Piper.run_command(cmd, options={}, script:nil,
79
+ usage:nil, synonyms:nil, mode:'r',
80
+ exception:nil, forward_pass:nil, **popt, &blk)
81
+ args,ret = options.to_args(usage:usage,synonyms:synonyms),nil
82
+ $stderr.puts "#{cmd} #{args.join(' ')}" if $DEBUG
83
+ IO.popen([cmd, *args], mode, **popt) do |pipe|
84
+ pipe.write script if script
85
+ if forward_pass
86
+ ret = forward_pass.call(pipe, options, blk)
87
+ elsif blk
88
+ ret = blk.call(pipe, options)
89
+ elsif mode=='r'
90
+ ret = pipe.read
91
+ elsif mode=='w+'
92
+ pipe.close_write
93
+ ret = pipe.read
94
+ end
95
+ end
96
+ # False exception instead of nil or "an error message"
97
+ # flags the expected behavior as defined:
98
+ success = ($?.exitstatus==0)
99
+ raise(exception) if exception and not success
100
+ return success if exception==false
101
+ return ret
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,40 @@
1
+ module Helpema
2
+ module Rubish
3
+ extend Piper
4
+ def Rubish.shell(name,
5
+ cmd:name.to_s.chomp('?').chomp('!'),
6
+ version:nil, v:nil,
7
+ usage:nil, synonyms:nil,
8
+ exception:nil, default:nil)
9
+ if name[-1]=='?'
10
+ mode = 'w'
11
+ exception = false unless exception
12
+ else
13
+ mode = 'w+'
14
+ end
15
+ Rubish.define_command(name.to_sym,
16
+ cmd:cmd,
17
+ version:version, v:v,
18
+ usage:usage, synonyms:synonyms,
19
+ mode:mode, exception:exception,
20
+ default:default) # default script
21
+ end
22
+ Rubish.shell :fish
23
+ Rubish.shell :fish?
24
+ Rubish.shell :bash
25
+ Rubish.shell :bash?
26
+ def Rubish.command(name,
27
+ cmd:name.to_s.chomp('?').chomp('!'),
28
+ version:nil, v:nil,
29
+ usage:nil, synonyms:nil, exception:nil)
30
+ mode = 'r'
31
+ exception = false if name[-1]=='?' and not exception
32
+ Rubish.define_command(name.to_sym,
33
+ cmd:cmd,
34
+ version:version, v:v,
35
+ usage:usage, synonyms:synonyms,
36
+ mode:mode, exception:exception)
37
+ end
38
+ extend self
39
+ end
40
+ end
data/lib/helpema/ssss.rb CHANGED
@@ -1,9 +1,13 @@
1
1
  module Helpema
2
2
  module SSSS
3
- extend Helpema
3
+ extend Piper
4
4
  class << self; attr_accessor :version; end
5
5
  SSSS.version = 'Version: 0\.[567]\b' # version as of this writing is 0.5
6
6
 
7
+ # To enforce a method signature, I wrap a `public` method around a
8
+ # `_private` `define_command` method. A `define_command` method looks like
9
+ # `_private(script=default,**options,&blk)`
10
+
7
11
  SSSS.define_command(:_split,
8
12
  cmd: 'ssss-split', v: SSSS.version,
9
13
  usage: {Q:true,t:2,n:3,w:nil,s:nil,x:false},
@@ -2,7 +2,7 @@ require 'json'
2
2
 
3
3
  module Helpema
4
4
  module YouTubeDL
5
- extend Helpema
5
+ extend Piper
6
6
  class << self; attr_accessor :version; end
7
7
  YouTubeDL.version = '^202\d\.[01]\d\.[0123]\d$'
8
8
 
@@ -24,13 +24,19 @@ module Helpema
24
24
  YouTubeDL.define_command(:_mp3,
25
25
  cmd: 'youtube-dl', version: YouTubeDL.version,
26
26
  usage: { output: nil,
27
+ format: true,
28
+ arg0: 'bestaudio',
27
29
  'extract-audio': true,
28
30
  'audio-format': true,
29
- arg0: 'mp3',
30
- arg1: nil },
31
- synonyms: {url: :arg1},
31
+ arg1: 'mp3',
32
+ 'audio-quality': true,
33
+ arg2: 0,
34
+ arg3: nil },
35
+ synonyms: {url: :arg3},
32
36
  err: '/dev/null')
33
- def mp3(url, output:'%(id)s.%(ext)s') = YouTubeDL._mp3(url:url, output:output)
37
+
38
+ def mp3(url, output:'%(id)s.%(ext)s') =
39
+ YouTubeDL._mp3(url:url, output:output)
34
40
 
35
41
  extend self
36
42
  end
data/lib/helpema/zbar.rb CHANGED
@@ -2,10 +2,10 @@ require 'tmpdir'
2
2
 
3
3
  module Helpema
4
4
  module ZBar
5
- extend Helpema
5
+ extend Piper
6
6
  class << self; attr_accessor :version, :screenshot; end
7
7
  ZBar.version = '^0\.2[345]\b' # version as of this writing is 0.23
8
- ZBar.screenshot = ['gnome-screenshot', '-f']
8
+ ZBar.screenshot = ['scrot']
9
9
 
10
10
  def snapshot(filename)
11
11
  system(*ZBar.screenshot, filename)
data/lib/helpema.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Helpema
2
- VERSION = '3.2.210924'
3
-
4
- require_relative 'helpema/helpema'
2
+ VERSION = '5.0.221213'
5
3
 
4
+ autoload :Piper, 'helpema/piper.rb'
5
+ autoload :Rubish, 'helpema/rubish.rb'
6
6
  autoload :SSSS, 'helpema/ssss.rb'
7
7
  autoload :YouTubeDL, 'helpema/youtubedl.rb'
8
8
  autoload :ZBar, 'helpema/zbar.rb'
@@ -17,5 +17,5 @@ end
17
17
  #`ssss-combine`
18
18
  #`zbarcam`
19
19
  #`zbarimg`
20
- #`gnome-screenshot`
20
+ #`scrot`
21
21
  #`gpg`
metadata CHANGED
@@ -1,19 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helpema
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.210924
4
+ version: 5.0.221213
5
5
  platform: ruby
6
6
  authors:
7
7
  - CarlosJHR64
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-24 00:00:00.000000000 Z
11
+ date: 2022-12-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
- Meant to be an eclectic collection of useful single functions and wrappers.
15
-
16
- Featured method: `requires "good ~>3.0", "bad ~>2.7", "ugly ~>1.8"`
14
+ Meant to be an eclectic collection of useful Linux command wrappers.
15
+ Facilitates creation of custom wrappers for any Linux command.
17
16
  email: carlosjhr64@gmail.com
18
17
  executables: []
19
18
  extensions: []
@@ -23,7 +22,8 @@ files:
23
22
  - lib/helpema.rb
24
23
  - lib/helpema/ffmpeg.rb
25
24
  - lib/helpema/gpg.rb
26
- - lib/helpema/helpema.rb
25
+ - lib/helpema/piper.rb
26
+ - lib/helpema/rubish.rb
27
27
  - lib/helpema/ssss.rb
28
28
  - lib/helpema/youtubedl.rb
29
29
  - lib/helpema/zbar.rb
@@ -31,7 +31,7 @@ homepage: https://github.com/carlosjhr64/helpema
31
31
  licenses:
32
32
  - MIT
33
33
  metadata: {}
34
- post_install_message:
34
+ post_install_message:
35
35
  rdoc_options: []
36
36
  require_paths:
37
37
  - lib
@@ -46,16 +46,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  requirements:
49
- - 'ruby: ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]'
50
- - 'youtube-dl: 2021.06.06'
49
+ - 'ruby: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [aarch64-linux]'
50
+ - 'youtube-dl: 2021.12.17'
51
51
  - 'ssss-split: 0.5'
52
52
  - 'ssss-combine: 0.5'
53
- - 'zbarcam: 0.23'
54
- - 'zbarimg: 0.23'
55
- - 'gnome-screenshot: gnome-screenshot 40.0'
53
+ - 'zbarcam: 0.23.90'
54
+ - 'zbarimg: 0.23.90'
55
+ - 'scrot: scrot version 1.5'
56
56
  - 'gpg: gpg (GnuPG) 2.2.27'
57
- rubygems_version: 3.2.22
58
- signing_key:
57
+ rubygems_version: 3.3.7
58
+ signing_key:
59
59
  specification_version: 4
60
- summary: Meant to be an eclectic collection of useful single functions and wrappers.
60
+ summary: Meant to be an eclectic collection of useful Linux command wrappers. Facilitates
61
+ creation of custom wrappers for any Linux command.
61
62
  test_files: []
@@ -1,118 +0,0 @@
1
- module Helpema
2
- refine ::String do
3
- def satisfies?(*reqs)
4
- Gem::Requirement.new(*reqs).satisfied_by? Gem::Version.new(self)
5
- end
6
- end
7
- refine ::Hash do
8
- def to_args(usage:nil, synonyms:nil)
9
- # create separate args from self with the translated synonyms
10
- args = self.transform_keys(synonyms.to_h)
11
- # pad usage's defaults to args
12
- usage&.each{|key,default| args[key]=default unless args.has_key? key}
13
- # order might be important so enforce usage
14
- args = usage&.map{|k,v|[k,args[k]]} || args.to_a
15
- # convert key,value tuples to final list of args
16
- args.map!(&:to_arg)
17
- # get rid of nil
18
- args.compact!
19
- # ...and finally flatten!
20
- args.flatten!
21
- return args
22
- end
23
- end
24
- refine ::Array do
25
- def classify(hash: Hash.new{|h,k|h[k]=[]})
26
- self.each{|v| hash[v.class] << v}
27
- return hash
28
- end
29
- def to_arg
30
- Helpema.to_arg(*self)
31
- end
32
- end
33
- refine ::Symbol do
34
- def to_flag
35
- return nil if self[-1].match?(/\d/) # like :arg0
36
- (self.length > 1)? "--#{self}": "-#{self}" # like --verbose or -V
37
- end
38
- end
39
- using Helpema
40
-
41
- def to_arg(key,value)
42
- # keep only keys with value(no false or nil)
43
- return nil unless value
44
- # assume nil0/--long/-short
45
- key = key.to_flag
46
- if key
47
- return key if value==true # a flag
48
- return "#{key}#{value}" if key[-1]=='=' # joined key=value
49
- return [key,value.to_s]
50
- end
51
- # It's a Nth arg, like arg0...
52
- return value.to_s
53
- end
54
-
55
- def run_command(cmd, options={},
56
- usage:nil, synonyms:nil, mode:'r',
57
- exception:nil, forward_pass:nil, **popt, &blk)
58
- args,ret = options.to_args(usage:usage,synonyms:synonyms),nil
59
- $stderr.puts "#{cmd} #{args.join(' ')}" if $DEBUG
60
- IO.popen([cmd, *args], mode, **popt) do |pipe|
61
- ret = forward_pass ? forward_pass.call(pipe, options, blk) :
62
- blk ? blk.call(pipe) :
63
- pipe.read
64
- end
65
- (exception.nil? or $?.exitstatus==0)? ret : raise(exception)
66
- end
67
-
68
- def define_command(name,
69
- cmd: name.to_s, version: nil, v: nil,
70
- usage: nil, synonyms: nil,
71
- mode: 'r',exception: nil,
72
- **popt, &forward_pass)
73
-
74
- # which version? --version or -v
75
- if version and not `#{cmd} --version`.strip.match?(version)
76
- raise "`#{cmd} --version` !~ #{version}"
77
- end
78
- if v and not `#{cmd} -v`.strip.match?(v)
79
- raise "`#{cmd} -v` !~ #{v}"
80
- end
81
-
82
- define_method(name) do |**options, &blk|
83
- run_command(cmd, options,
84
- usage:usage, synonyms:synonyms, mode:mode,
85
- exception:exception, forward_pass:forward_pass, **popt, &blk)
86
- end
87
- end
88
-
89
- def requires(*list)
90
- loaded = []
91
- list.each do |gems|
92
- gems.lines.each do |gemname_reqs|
93
- gemname, *reqs = gemname_reqs.split
94
- next unless gemname
95
- unless reqs.empty?
96
- case gemname
97
- when 'helpema'
98
- unless VERSION.satisfies?(*reqs)
99
- raise "helpema #{VERSION} not #{reqs.join(', ')}"
100
- end
101
- next
102
- when 'ruby'
103
- unless RUBY_VERSION.satisfies?(*reqs)
104
- raise "ruby #{RUBY_VERSION} not #{reqs.join(', ')}"
105
- end
106
- next
107
- else
108
- gem gemname, *reqs
109
- end
110
- end
111
- require gemname and loaded.push gemname
112
- end
113
- end
114
- return loaded
115
- end
116
-
117
- extend self
118
- end