whatoption 0.2.0 → 0.3.0

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/whatoption +44 -24
  3. data/lib/whatoption.rb +25 -8
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eba18bf18642b07d11d846b7abbaf16932df2b47ac8a86128243ae5c4a0e5825
4
- data.tar.gz: 487e4c5d7fb30d871deeefcf04f80b9a6f9d82bc80a8cbd4167b25ab27cfaa77
3
+ metadata.gz: 8ae23eb231b87c00885211c51e42ec78fa2d4b5fac7af36163c86a49478ade52
4
+ data.tar.gz: fa93f8e92fc55b95574830fc323bc854708c00c201a01afd5db802f11f496842
5
5
  SHA512:
6
- metadata.gz: 0d945a051921d4b807594f203ab8fc96008e3c392126bd841ffab2d3d280016f9d6bb33a7d718c6ae7a6aeb970aba4d56a3c923ca3ee6ba95c2866843c1921c2
7
- data.tar.gz: 11f2853c227dcb57fd037a28c809ef1325c7a9eb050e02f8eacf5294656c7edccdd482a82e90bb1ab2ff5db182209b8f59e281cafe0402c374a2f8eac4f36ede
6
+ metadata.gz: 27824e60eb11034c9e1f4b0f26a8732bb67a68514ce492a5ea1561314aa4ae290ff7f89fed0d6e8ceb53be7a97cacdc36536885d618daf0b213c37d09c99ccaa
7
+ data.tar.gz: e4a563e68423ce659244a67edc9d8542f8b612e6db856746be164f827c84a52fe3b691d88d4363fbfb0525f77f7276e016915e062eb259539f72ae0d5dd69c6e
data/bin/whatoption CHANGED
@@ -1,20 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
  # ---------------------------------------------------------------
3
3
  # File : whatoption.rb
4
- # Authors : ccmywish <ccmywish@qq.com>
4
+ # Authors : Aoran Zeng <ccmywish@qq.com>
5
5
  # Created on : <2023-02-06>
6
- # Last modified : <2023-02-07>
6
+ # Last modified : <2023-03-14>
7
7
  # Contributors :
8
8
  #
9
9
  # whatoption:
10
10
  #
11
11
  # Tells you what the option of the command means.
12
12
  #
13
- # ----------
14
- # Changelog:
15
- #
16
- # ~> v0.1.0
17
- # <2023-02-06> Create file
18
13
  # ---------------------------------------------------------------
19
14
 
20
15
  require 'whatoption'
@@ -26,6 +21,9 @@ require 'whatoption'
26
21
  class WhatOption::CliHandler
27
22
 
28
23
  def initialize(argv)
24
+
25
+ @argv = argv
26
+
29
27
  if argv.empty?
30
28
  help || return
31
29
  end
@@ -43,18 +41,12 @@ class WhatOption::CliHandler
43
41
  puts cmd = "git -C #{WhatOption::OPTIONS_DATA_DIR} pull"
44
42
  system cmd
45
43
  return
44
+ when '-l'
45
+ list_options
46
+ else
47
+ get_option
46
48
  end
47
49
 
48
- if argv.size == 1
49
- puts("Please input the option for command '#{argv[0]}'".red) || return
50
- end
51
-
52
- @option = ARGV[-1] # Shouldn't detect where is begin with '-' or '--'
53
- # because some options are just single characters,
54
- # for example, 'tar x', this is to use subcommand as option
55
- # That's reasonable also.
56
- @commands = ARGV[0...-1]
57
-
58
50
  # p option
59
51
  # p commands
60
52
  end
@@ -70,9 +62,10 @@ class WhatOption::CliHandler
70
62
 
71
63
  Options:
72
64
 
73
- -u Update ~/.whatoption data
74
- -h Print this help
75
- -v Print version
65
+ -u Update ~/.whatoption data
66
+ -l <command> List command options
67
+ -h Print this help
68
+ -v Print version
76
69
 
77
70
  Examples:
78
71
 
@@ -85,17 +78,44 @@ class WhatOption::CliHandler
85
78
  HELP
86
79
  end
87
80
 
88
- # method
89
- def work
81
+
82
+ # routine
83
+ def get_option
84
+
85
+ if @argv.size == 1
86
+ puts("Please input the option for command '#{@argv[0]}'".red) || return
87
+ end
88
+
89
+ option = ARGV[-1] # Shouldn't detect where is begin with '-' or '--'
90
+ # because some options are just single characters,
91
+ # for example, 'tar x', this is to use subcommand as option
92
+ # That's reasonable also.
93
+ commands = ARGV[0...-1]
94
+
90
95
  # Because the initializer above will not always finish initializing
91
96
  if (not @commands) || (not @option)
92
97
  exit
93
98
  end
94
- option_info = WhatOption::OptionInfo.new @commands, @option
99
+ option_info = WhatOption::OptionInfo.new commands, option
95
100
  option_info.show
96
101
  end
97
102
 
103
+
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
+
111
+ option = nil
112
+ commands = ARGV[1..-1]
113
+ option_info = WhatOption::OptionInfo.new commands, option
114
+ option_info.list
115
+ end
116
+
117
+
98
118
  end
99
119
 
120
+ # main
100
121
  cli = WhatOption::CliHandler.new ARGV
101
- cli.work
data/lib/whatoption.rb CHANGED
@@ -1,23 +1,18 @@
1
1
  # ---------------------------------------------------------------
2
2
  # File : whatoption.rb
3
- # Authors : ccmywish <ccmywish@qq.com>
3
+ # Authors : Aoran Zeng <ccmywish@qq.com>
4
4
  # Created on : <2023-02-06>
5
- # Last modified : <2023-02-07>
5
+ # Last modified : <2023-03-14>
6
6
  #
7
7
  # whatoption:
8
8
  #
9
9
  # Lib file
10
10
  #
11
- # ----------
12
- # Changelog:
13
- #
14
- # ~> v0.1.0
15
- # <2023-02-06> Create file
16
11
  # ---------------------------------------------------------------
17
12
 
18
13
  module WhatOption
19
14
 
20
- VERSION = "0.2.0"
15
+ VERSION = "0.3.0"
21
16
 
22
17
  require 'pathname'
23
18
  OPTIONS_DATA_DIR = Pathname.new File.expand_path("~/.whatoption")
@@ -91,6 +86,28 @@ module WhatOption
91
86
  end
92
87
 
93
88
 
89
+ # method
90
+ def list
91
+ sheet = load_sheet
92
+ if not sheet
93
+ exit 1
94
+ end
95
+
96
+ option_max_len = sheet.keys.map(&:length).max
97
+ left = option_max_len + 3
98
+
99
+ lmda = -> hash do hash['desc'].length end
100
+ desc_max_len = sheet.values.map(&lmda).max
101
+
102
+ middle = desc_max_len + 3
103
+
104
+ puts "Options for '#{@commands.join}':"
105
+ sheet.each do |key, value|
106
+ printf " %s%s%s\n", key.ljust(left), value['desc'].ljust(middle), value['func']
107
+ end
108
+ end
109
+
110
+
94
111
  # routine
95
112
  def resolve
96
113
  sheet = load_sheet
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ccmywish
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-08 00:00:00.000000000 Z
11
+ date: 2023-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tomlrb
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  requirements: []
76
- rubygems_version: 3.3.26
76
+ rubygems_version: 3.4.1
77
77
  signing_key:
78
78
  specification_version: 4
79
79
  summary: 'whatoption: What does the option mean?'