whatoption 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/{bin → exe}/whatoption +22 -30
  3. data/lib/whatoption.rb +22 -27
  4. metadata +22 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c63a49419c51f74f67a91a8f064182e0edad18ea31db1ed86a17cc0022eda091
4
- data.tar.gz: 840b7599e54ea02c20357e8d653ec6c4ba04aa7c0743983c74ddcec73e45dfb2
3
+ metadata.gz: c8ecf74dab1f9a4bd5cccccd8cc0e5f00af1534e98cd54f249602839e24d2c1e
4
+ data.tar.gz: 4eb9546b5d1eff5b74834a54c18005d2a983959d4cb316ba8d2f3537dd5df177
5
5
  SHA512:
6
- metadata.gz: b5753baf60b7353155c9154495a33c33f10403556f2e73968d650a8fff657e61c25dda3ebb1163491f6d48fa36c5c0c02efc6766fe06c85e6589712df5a4effa
7
- data.tar.gz: 4468ab208fcc6e0bd24d13307b9f58fcb1939d4ac39b3566c48767aed093dd79958fada73160149fd59ba3e454cf81633c478fe83d898c66d6df938bbf04d3e6
6
+ metadata.gz: d035043abc9afc51b1491759309dea683f588c078e7e7fac25970e0985b48ed34cde42fd2b433eeeb43544c187e431b3fdb07b2c1dab8f6ac5e52f483dc60aa6
7
+ data.tar.gz: 23cb626f7b24ef9fa2aaa0c5925756ccfae9473348489f653020845a6edd8345384307208a389a1ad18df84dc4ca7113131b27e15a9b9e641228e58da9f0b788
@@ -3,24 +3,27 @@
3
3
  # File : whatoption.rb
4
4
  # Authors : Aoran Zeng <ccmywish@qq.com>
5
5
  # Created on : <2023-02-06>
6
- # Last modified : <2023-03-14>
7
- # Contributors :
6
+ # Last modified : <2023-08-15>
8
7
  #
9
8
  # whatoption:
10
9
  #
11
10
  # Tells you what the option of the command means.
12
- #
13
11
  # ---------------------------------------------------------------
14
12
 
15
13
  require 'whatoption'
16
14
 
15
+ require 'rainbow/refinement'
16
+ using Rainbow
17
+
17
18
  ####################
18
19
  # main
19
20
  ####################
20
21
 
21
- class WhatOption::CliHandler
22
+ class WhatOption::CLI
23
+
24
+ def self.run
22
25
 
23
- def initialize(argv)
26
+ argv = ARGV.dup
24
27
 
25
28
  @argv = argv
26
29
 
@@ -35,14 +38,12 @@ class WhatOption::CliHandler
35
38
  puts("WhatOption v#{WhatOption::VERSION}") || return
36
39
  when '-u'
37
40
  # This output will be hided into the return string
38
- # `git -C #{WhatOption::OPTIONS_DATA_DIR} pull`
41
+ # `git -C "#{WhatOption::OPTIONS_DATA_DIR}" pull`
39
42
 
40
43
  # So we use system()
41
- puts cmd = "git -C #{WhatOption::OPTIONS_DATA_DIR} pull"
44
+ puts cmd = "git -C '#{WhatOption::OPTIONS_DATA_DIR}' pull"
42
45
  system cmd
43
46
  return
44
- when '-l'
45
- list_options
46
47
  else
47
48
  get_option
48
49
  end
@@ -51,24 +52,21 @@ class WhatOption::CliHandler
51
52
  # p commands
52
53
  end
53
54
 
54
- # routine
55
- def help
55
+
56
+ def self.help
56
57
  puts("WhatOption v#{WhatOption::VERSION}")
57
58
  puts
58
59
  puts <<~HELP
59
60
  Usage:
61
+ whatoption <command> [subcommands] <option>
60
62
 
61
- whatoption command subcommands option
62
-
63
- Options:
64
-
65
- -u Update ~/.whatoption data
66
- -l <command> List command options
63
+ Switches:
64
+ -u Update options data
67
65
  -h Print this help
68
66
  -v Print version
69
67
 
70
68
  Examples:
71
-
69
+ whatoption rpm
72
70
  whatoption ruby -c
73
71
  whatoption tar x
74
72
  whatoption git ls-files -z
@@ -79,11 +77,11 @@ class WhatOption::CliHandler
79
77
  end
80
78
 
81
79
 
82
- # routine
83
- def get_option
80
+ def self.get_option
84
81
 
85
82
  if @argv.size == 1
86
- puts("Please input the option for command '#{@argv[0]}'".red) || return
83
+ # puts("Please input the option for command '#{@argv[0]}'".red) || return
84
+ return list_options
87
85
  end
88
86
 
89
87
  option = ARGV[-1] # Shouldn't detect where is begin with '-' or '--'
@@ -101,15 +99,9 @@ class WhatOption::CliHandler
101
99
  end
102
100
 
103
101
 
104
- # routine
105
- def list_options
106
-
107
- if @argv.size == 1
108
- puts("Please input the command name after '-l'".red) || return
109
- end
110
-
102
+ def self.list_options
111
103
  option = nil
112
- commands = ARGV[1..-1]
104
+ commands = [ARGV[0]]
113
105
  option_info = WhatOption::OptionInfo.new commands, option
114
106
  option_info.list
115
107
  end
@@ -118,4 +110,4 @@ class WhatOption::CliHandler
118
110
  end
119
111
 
120
112
  # main
121
- cli = WhatOption::CliHandler.new ARGV
113
+ WhatOption::CLI.run
data/lib/whatoption.rb CHANGED
@@ -2,30 +2,32 @@
2
2
  # File : whatoption.rb
3
3
  # Authors : Aoran Zeng <ccmywish@qq.com>
4
4
  # Created on : <2023-02-06>
5
- # Last modified : <2023-03-14>
5
+ # Last modified : <2023-08-15>
6
6
  #
7
7
  # whatoption:
8
8
  #
9
9
  # Lib file
10
- #
11
10
  # ---------------------------------------------------------------
12
11
 
12
+ require 'rainbow/refinement'
13
+ using Rainbow
14
+
13
15
  module WhatOption
14
16
 
15
- VERSION = "0.3.1"
17
+ VERSION = "0.3.3"
16
18
 
19
+ require 'standard_path'
17
20
  require 'pathname'
18
- OPTIONS_DATA_DIR = Pathname.new File.expand_path("~/.whatoption")
19
21
 
20
- if not Dir.exist? OPTIONS_DATA_DIR
21
- `git clone https://github.com/ccmywish/whatoption.toml #{OPTIONS_DATA_DIR}`
22
+ WhatOption_DATA_DIR = Pathname.new StandardPath.app_data 'WhatOption'
23
+
24
+ if not Dir.exist? WhatOption_DATA_DIR
25
+ `git clone https://github.com/ccmywish/WhatOptionData "#{WhatOption_DATA_DIR}"`
22
26
  end
23
27
 
24
28
 
25
29
  class OptionInfo
26
30
 
27
- require 'colorator'
28
-
29
31
  =begin
30
32
 
31
33
  attribute:
@@ -62,10 +64,10 @@ module WhatOption
62
64
  require 'tomlrb'
63
65
  # It's very interesting here, you have to put parentheses then 'commands.join()' is
64
66
  # treated as a string.
65
- # Without parentheses, the + is affected by OPTIONS_DATA_DIR,
67
+ # Without parentheses, the + is affected by WhatOption_DATA_DIR,
66
68
  # So first '+'s both side are Pathname
67
69
  # And '+' is to add a '/' to component
68
- @file = OPTIONS_DATA_DIR + (@commands.join('/') + ".toml")
70
+ @file = WhatOption_DATA_DIR + (@commands.join('/') + ".toml")
69
71
 
70
72
  # if the file not exists, it is maybe in the dir (with its own name)
71
73
  # For example:
@@ -89,9 +91,7 @@ module WhatOption
89
91
  # method
90
92
  def list
91
93
  sheet = load_sheet
92
- if not sheet
93
- exit 1
94
- end
94
+ abort if not sheet
95
95
 
96
96
  option_max_len = sheet.keys.map(&:length).max
97
97
  left = option_max_len + 3
@@ -101,9 +101,11 @@ module WhatOption
101
101
 
102
102
  middle = desc_max_len + 3
103
103
 
104
- puts "Options for '#{@commands.join}':"
104
+ print "Options for ", @commands.join.yellow, ":\n"
105
105
  sheet.each do |key, value|
106
- printf " %s%s%s\n", key.ljust(left), value['desc'].ljust(middle), value['func']
106
+ printf " %s%s%s\n", key.ljust(left).magenta,
107
+ value['desc'].ljust(middle).green,
108
+ value['func']
107
109
  end
108
110
  end
109
111
 
@@ -111,22 +113,16 @@ module WhatOption
111
113
  # routine
112
114
  def resolve
113
115
  sheet = load_sheet
114
- if not sheet
115
- exit 1
116
- end
116
+ abort if not sheet
117
117
 
118
118
  record = sheet[@option] ||
119
- puts("Error: Option [#@option] is not recorded in #@file".red) ||
120
- exit(1)
119
+ puts("Error: Option [#@option] is not recorded in #@file".red) || abort
121
120
  @rec_usage = record['usage'] ||
122
- puts("Error: No field 'usage' in #@file [#@calling_command]".red) ||
123
- exit(1)
121
+ puts("Error: No field 'usage' in #@file [#@calling_command]".red) || abort
124
122
  @rec_desc = record['desc'] ||
125
- puts("Error: No field 'desc' in #@file [#@calling_command]".red) ||
126
- exit(1)
123
+ puts("Error: No field 'desc' in #@file [#@calling_command]".red) || abort
127
124
  @rec_func = record['func'] ||
128
- puts("Error: No field 'func' in #@file [#@calling_command]".red) ||
129
- exit(1)
125
+ puts("Error: No field 'func' in #@file [#@calling_command]".red) || abort
130
126
  end
131
127
 
132
128
 
@@ -151,5 +147,4 @@ module WhatOption
151
147
 
152
148
  end
153
149
 
154
-
155
150
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whatoption
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ccmywish
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-15 00:00:00.000000000 Z
11
+ date: 2023-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tomlrb
@@ -25,19 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: colorator
28
+ name: standard_path
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.1'
33
+ version: '0.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.1'
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rainbow
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
41
55
  description: 'This command line tool `whatoption` is used to record and explain commands''
42
56
  options, so there is no need to run the command itself to check what the help info
43
57
  is. Besides, many options only have one character, which is sometimes not easily
@@ -50,7 +64,7 @@ executables:
50
64
  extensions: []
51
65
  extra_rdoc_files: []
52
66
  files:
53
- - bin/whatoption
67
+ - exe/whatoption
54
68
  - lib/whatoption.rb
55
69
  homepage: https://github.com/ccmywish/whatoption
56
70
  licenses:
@@ -73,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
87
  - !ruby/object:Gem::Version
74
88
  version: '0'
75
89
  requirements: []
76
- rubygems_version: 3.3.26
90
+ rubygems_version: 3.4.8
77
91
  signing_key:
78
92
  specification_version: 4
79
93
  summary: 'whatoption: What does the option mean?'