machine_configure 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -2
- data/Gemfile.lock +1 -8
- data/lib/argument_parser.rb +112 -0
- data/lib/machine_configure.rb +1 -1
- data/lib/machine_configure/meta.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06ef93f9530db48a7db44d49b441113df4f1e067a07a60a73b13fcf1325523aa
|
4
|
+
data.tar.gz: b618dabc8e2d8fbef51b19d399658fa89850feed80578cdad3315a2e6cbf56a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 242859e7737e8e29983c379d72f5bdbed420f5d26f086397c823f118d98da51df9c4402cd29203ba111c38f8f33a5c98432fc5db2e74a6e652903e2d71ecd9c5
|
7
|
+
data.tar.gz: e4fe37d37a2e72b9a24ec17d7c72ebf18a4cec9cf6146c591bf3fb41bb04180bd8efa09630e1aca81d0c54b96583671a87b14caf67526d62667abb6dac8b8ceb
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,7 @@
|
|
1
|
-
GIT
|
2
|
-
remote: https://github.com/Noah2610/ArgumentParser
|
3
|
-
revision: 3ac5b0083fd42ae8740d1d22d988f56c74a29470
|
4
|
-
specs:
|
5
|
-
argument_parser (1.0.0)
|
6
|
-
|
7
1
|
PATH
|
8
2
|
remote: .
|
9
3
|
specs:
|
10
|
-
machine_configure (0.0.
|
4
|
+
machine_configure (0.0.2)
|
11
5
|
rubyzip (~> 1.2)
|
12
6
|
|
13
7
|
GEM
|
@@ -22,7 +16,6 @@ PLATFORMS
|
|
22
16
|
ruby
|
23
17
|
|
24
18
|
DEPENDENCIES
|
25
|
-
argument_parser!
|
26
19
|
bundler (~> 1.16)
|
27
20
|
machine_configure!
|
28
21
|
minitest (~> 5.0)
|
@@ -0,0 +1,112 @@
|
|
1
|
+
####################################################
|
2
|
+
## Simple command-line arguments / options parser ##
|
3
|
+
## https://github.com/Noah2610/ArgumentParser ##
|
4
|
+
####################################################
|
5
|
+
|
6
|
+
class ArgumentParser
|
7
|
+
def self.get_arguments valid_args = {}
|
8
|
+
return nil if (valid_args.nil? || valid_args.empty?)
|
9
|
+
|
10
|
+
ret = {
|
11
|
+
options: {},
|
12
|
+
keywords: {}
|
13
|
+
}
|
14
|
+
|
15
|
+
set_opt_val_of = nil
|
16
|
+
set_kw_val_of = nil
|
17
|
+
cur_kw_chain = nil
|
18
|
+
read_user_inputs = false
|
19
|
+
## Loop through all command-line arguments
|
20
|
+
ARGV.each do |argument|
|
21
|
+
|
22
|
+
## Check valid SINGLE options
|
23
|
+
if (argument =~ /\A-[\w\d]+\z/)
|
24
|
+
## Get all options of argument
|
25
|
+
cur_opts = argument.sub(/\A-/,"").split("")
|
26
|
+
valid_args[:single].each do |id, val|
|
27
|
+
## Loop through every command-line option of current argument
|
28
|
+
# ex.: -abc -> a,b,c
|
29
|
+
cur_opts.each do |opt|
|
30
|
+
if (val.first.include? opt)
|
31
|
+
## Check if option takes value
|
32
|
+
if (val.last)
|
33
|
+
ret[:options][id] = nil
|
34
|
+
set_opt_val_of = id
|
35
|
+
else
|
36
|
+
ret[:options][id] = true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
## Check valid DOUBLE options
|
43
|
+
elsif (argument =~ /\A--[\w\d\-]+\z/)
|
44
|
+
cur_opt = argument.sub(/\A--/,"")
|
45
|
+
valid_args[:double].each do |id, val|
|
46
|
+
if (val.first.include? cur_opt)
|
47
|
+
## Check if option takes value
|
48
|
+
if (val.last)
|
49
|
+
ret[:options][id] = nil
|
50
|
+
set_opt_val_of = id
|
51
|
+
else
|
52
|
+
ret[:options][id] = true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
## Check valid KEYWORDS or values
|
58
|
+
elsif !(argument =~ /\A-{1,2}/)
|
59
|
+
## Set value of previously found option
|
60
|
+
if (set_opt_val_of)
|
61
|
+
ret[:options][set_opt_val_of] = argument
|
62
|
+
set_opt_val_of = nil
|
63
|
+
next
|
64
|
+
elsif (set_kw_val_of)
|
65
|
+
ret[:keywords][set_kw_val_of] << argument
|
66
|
+
set_kw_val_of = nil
|
67
|
+
next
|
68
|
+
end
|
69
|
+
|
70
|
+
## Check if in kw-chain or for valid keyword
|
71
|
+
if (cur_kw_chain.nil?)
|
72
|
+
valid_args[:keywords].each do |id, val|
|
73
|
+
if ([:INPUT, :INPUTS].include?(val.first) || val.first.include?(argument))
|
74
|
+
ret[:keywords][id] = [argument]
|
75
|
+
cur_kw_chain = id
|
76
|
+
break
|
77
|
+
end
|
78
|
+
end
|
79
|
+
else
|
80
|
+
## Check if argument is valid for next kw in kw-chain
|
81
|
+
kw_chain_index = ret[:keywords][cur_kw_chain].size
|
82
|
+
## Read unlimited custom user input
|
83
|
+
if (read_user_inputs)
|
84
|
+
ret[:keywords][cur_kw_chain] << argument
|
85
|
+
next
|
86
|
+
else
|
87
|
+
## If not unlimited custom user input and argument's length has exceeded
|
88
|
+
## keyword-chain's possible length, then skip
|
89
|
+
next if (kw_chain_index >= valid_args[:keywords][cur_kw_chain].size)
|
90
|
+
end
|
91
|
+
if (valid_args[:keywords][cur_kw_chain][kw_chain_index] == :INPUT)
|
92
|
+
## Custom user input (single)
|
93
|
+
ret[:keywords][cur_kw_chain] << argument
|
94
|
+
|
95
|
+
elsif (valid_args[:keywords][cur_kw_chain][kw_chain_index] == :INPUTS)
|
96
|
+
## Custom user input (unlimited)
|
97
|
+
ret[:keywords][cur_kw_chain] << argument
|
98
|
+
read_user_inputs = true
|
99
|
+
|
100
|
+
else
|
101
|
+
if (valid_args[:keywords][cur_kw_chain][kw_chain_index].include? argument)
|
102
|
+
ret[:keywords][cur_kw_chain] << argument
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end # end arguments loop
|
109
|
+
|
110
|
+
return ret
|
111
|
+
end
|
112
|
+
end
|
data/lib/machine_configure.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'bundler/setup'
|
2
|
-
require 'argument_parser'
|
3
2
|
require 'fileutils'
|
4
3
|
require 'pathname'
|
5
4
|
require 'zip'
|
@@ -43,6 +42,7 @@ module MachineConfigure
|
|
43
42
|
DM_BACKUP_CERTS_PATH = DM_BACKUP_PATH.join('certs')
|
44
43
|
|
45
44
|
require DIR[:src].join 'meta'
|
45
|
+
require DIR[:root].join 'argument_parser'
|
46
46
|
require DIR[:helpers].join 'shared'
|
47
47
|
require DIR[:helpers].join 'message'
|
48
48
|
require DIR[:src].join 'validator'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: machine_configure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noah Rosenzweig
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- bin/rdoc
|
103
103
|
- bin/setup
|
104
104
|
- exe/maccon
|
105
|
+
- lib/argument_parser.rb
|
105
106
|
- lib/machine_configure.rb
|
106
107
|
- lib/machine_configure/cli.rb
|
107
108
|
- lib/machine_configure/cli_constants.rb
|