goldman 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +0 -18
- data/exe/goldman +3 -55
- data/lib/goldman/cli.rb +72 -0
- data/lib/goldman/config.rb +5 -1
- data/lib/goldman/formatter.rb +14 -0
- data/lib/goldman/version.rb +1 -1
- data/lib/goldman.rb +1 -14
- data/pkg/.keep +0 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f1879b6e3dde08040bc60cbd042d30fd6d8033b69d0324c18572001af199bc6
|
4
|
+
data.tar.gz: 2cb786913beaf9da72d3e3c9d8ea98d13930e8957bae83f47f6f159235eedccb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d43fbbf48bd7f062ed6a0fbe02f2d74d1c7da1c7aa5f8c9d186ac80bf0dbc94c660663e15144065ef3f976e576d4151f0438b466d652aafe2f866e3c6cc5fec
|
7
|
+
data.tar.gz: bbaeca4190f77c282715f486fb0a256ad5218888451d6aad5469119883ca942b4f0fbb3f4e5acd56876ab704b0fc044e25b0dfbf8a7f72b8d73bb4feee80b403
|
data/Rakefile
CHANGED
@@ -14,21 +14,3 @@ require "rubocop/rake_task"
|
|
14
14
|
RuboCop::RakeTask.new
|
15
15
|
|
16
16
|
task default: %i[test rubocop]
|
17
|
-
|
18
|
-
namespace "gem" do
|
19
|
-
desc "Build a gem package"
|
20
|
-
task :build do
|
21
|
-
sh "gem build goldman.gemspec"
|
22
|
-
end
|
23
|
-
|
24
|
-
desc "Push a gem package"
|
25
|
-
task :push do
|
26
|
-
Rake::Task["gem:build"].execute
|
27
|
-
sh "gem push goldman-#{Goldman::VERSION}.gem"
|
28
|
-
end
|
29
|
-
|
30
|
-
desc "Clean built gem packages"
|
31
|
-
task :clean do
|
32
|
-
sh "rm goldman-*.gem"
|
33
|
-
end
|
34
|
-
end
|
data/exe/goldman
CHANGED
@@ -5,62 +5,10 @@
|
|
5
5
|
# MIT license
|
6
6
|
|
7
7
|
require "goldman"
|
8
|
-
require "optparse"
|
9
|
-
|
10
|
-
DEFAULT_CONFIG_FILEPATH = ENV["GOLDMAN_RB_PATH"] || File.expand_path("~/.goldman/config.yml")
|
11
|
-
NON_OPERATIONAL_OPTS = [:config]
|
12
|
-
|
13
|
-
# default value
|
14
|
-
@options = {
|
15
|
-
config: DEFAULT_CONFIG_FILEPATH
|
16
|
-
}
|
17
|
-
|
18
|
-
opts = OptionParser.new do |opts|
|
19
|
-
opts.on("-c", "--config FILE", "Use a config file") { |v| @options[:config] = v }
|
20
|
-
opts.on("-g", "--generate", "Generate list of schedule options") { |v| @options[:generate] = v }
|
21
|
-
opts.on("-s", "--start [DATE]", "Set start date") { |v| @options[:start_date] = v }
|
22
|
-
opts.on("-e", "--end [DATE]", "Set end date") { |v| @options[:end_date] = v }
|
23
|
-
opts.on("-d", "--day [INTEGER]", "Set day interval from start date") { |v| @options[:day] = v }
|
24
|
-
opts.on("-w", "--week [INTEGER]", "Set week interval from start date") { |v| @options[:week] = v }
|
25
|
-
opts.on("-v", "--version", "Show tool version") { |v| @options[:version] = v }
|
26
|
-
|
27
|
-
opts.parse!(ARGV)
|
28
|
-
end
|
29
|
-
|
30
|
-
def error(message)
|
31
|
-
warn "ERROR: #{message}"
|
32
|
-
exit 1
|
33
|
-
end
|
34
8
|
|
35
9
|
begin
|
36
|
-
|
37
|
-
start_date_str: @options[:start_date],
|
38
|
-
end_date_str: @options[:end_date],
|
39
|
-
day_str: @options[:day],
|
40
|
-
week_str: @options[:week]
|
41
|
-
).to_a
|
42
|
-
config = Goldman::Config.new(path: @options[:config])
|
43
|
-
formatter = Goldman::Formatter.new(customized: config.format)
|
44
|
-
list = Goldman::ScheduleList.new(
|
45
|
-
data: config.data,
|
46
|
-
dates: dates
|
47
|
-
).generate
|
48
|
-
|
49
|
-
@options.each do |k, v|
|
50
|
-
case k
|
51
|
-
when :generate
|
52
|
-
Goldman::Presenter.print_schedule_list(
|
53
|
-
list: list,
|
54
|
-
formatter: formatter
|
55
|
-
)
|
56
|
-
when *NON_OPERATIONAL_OPTS
|
57
|
-
# Do nothing here
|
58
|
-
when :version
|
59
|
-
Goldman.version
|
60
|
-
end
|
61
|
-
end
|
10
|
+
Goldman::Cli.new(ARGV).run
|
62
11
|
rescue Goldman::Error => ex
|
63
|
-
|
64
|
-
|
65
|
-
error "Config file (#{@options[:config]}) dose not exist."
|
12
|
+
warn "ERROR: #{ex}"
|
13
|
+
exit 1
|
66
14
|
end
|
data/lib/goldman/cli.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "optparse"
|
4
|
+
|
5
|
+
module Goldman
|
6
|
+
class Cli
|
7
|
+
NON_OPERATIONAL_OPTS = [:config]
|
8
|
+
|
9
|
+
def initialize(argv)
|
10
|
+
@options = parse_argv(argv)
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
@options.each do |k, v|
|
15
|
+
case k
|
16
|
+
when :generate
|
17
|
+
cmd_generate
|
18
|
+
when *NON_OPERATIONAL_OPTS
|
19
|
+
# Do nothing here
|
20
|
+
when :version
|
21
|
+
cmd_version
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def cmd_generate
|
27
|
+
dates = Goldman::DateRange.new(
|
28
|
+
start_date_str: @options[:start_date],
|
29
|
+
end_date_str: @options[:end_date],
|
30
|
+
day_str: @options[:day],
|
31
|
+
week_str: @options[:week]
|
32
|
+
).to_a
|
33
|
+
config = Goldman::Config.new(path: @options[:config])
|
34
|
+
formatter = Goldman::Formatter.new(customized: config.format)
|
35
|
+
list = Goldman::ScheduleList.new(
|
36
|
+
data: config.data,
|
37
|
+
dates: dates
|
38
|
+
).generate
|
39
|
+
|
40
|
+
Goldman::Presenter.print_schedule_list(
|
41
|
+
list: list,
|
42
|
+
formatter: formatter
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
def cmd_version
|
47
|
+
Goldman.version
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def parse_argv(argv)
|
53
|
+
# default value
|
54
|
+
options = {
|
55
|
+
config: ENV["GOLDMAN_RB_PATH"] || File.expand_path("~/.goldman/config.yml")
|
56
|
+
}
|
57
|
+
|
58
|
+
OptionParser.new do |opts|
|
59
|
+
opts.on("-c", "--config FILE", "Use a config file") { |v| options[:config] = v }
|
60
|
+
opts.on("-g", "--generate", "Generate list of schedule options") { |v| options[:generate] = v }
|
61
|
+
opts.on("-s", "--start [DATE]", "Set start date") { |v| options[:start_date] = v }
|
62
|
+
opts.on("-e", "--end [DATE]", "Set end date") { |v| options[:end_date] = v }
|
63
|
+
opts.on("-d", "--day [INTEGER]", "Set day interval from start date") { |v| options[:day] = v }
|
64
|
+
opts.on("-w", "--week [INTEGER]", "Set week interval from start date") { |v| options[:week] = v }
|
65
|
+
opts.on("-v", "--version", "Show tool version") { |v| options[:version] = v }
|
66
|
+
opts.parse!(argv)
|
67
|
+
end
|
68
|
+
|
69
|
+
return options
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/goldman/config.rb
CHANGED
@@ -16,7 +16,11 @@ module Goldman
|
|
16
16
|
private
|
17
17
|
|
18
18
|
def load_file
|
19
|
-
|
19
|
+
begin
|
20
|
+
Psych.safe_load_file(@path, symbolize_names: true)
|
21
|
+
rescue Errno::ENOENT
|
22
|
+
raise Goldman::ConfigurationError.new("Config file (#{@path}) dose not exist.")
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
def load_data
|
data/lib/goldman/formatter.rb
CHANGED
@@ -2,6 +2,20 @@
|
|
2
2
|
|
3
3
|
module Goldman
|
4
4
|
class Formatter
|
5
|
+
DEFAULT_FORMAT = {
|
6
|
+
schedule: "%{date}(%{wday}) %{time}",
|
7
|
+
date: "%Y/%m/%d",
|
8
|
+
wday: {
|
9
|
+
Monday: "Mon",
|
10
|
+
Tuesday: "Tue",
|
11
|
+
Wednesday: "Wed",
|
12
|
+
Thursday: "Thu",
|
13
|
+
Friday: "Fri",
|
14
|
+
Saturday: "Sat",
|
15
|
+
Sunday: "Sun"
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
5
19
|
attr_reader :customized_format, :default_format
|
6
20
|
|
7
21
|
def initialize(customized:, default: DEFAULT_FORMAT)
|
data/lib/goldman/version.rb
CHANGED
data/lib/goldman.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "goldman/cli"
|
3
4
|
require_relative "goldman/config"
|
4
5
|
require_relative "goldman/date_range"
|
5
6
|
require_relative "goldman/formatter"
|
@@ -9,20 +10,6 @@ require_relative "goldman/version"
|
|
9
10
|
require_relative "goldman/wday"
|
10
11
|
|
11
12
|
module Goldman
|
12
|
-
DEFAULT_FORMAT = {
|
13
|
-
schedule: "%{date}(%{wday}) %{time}",
|
14
|
-
date: "%Y/%m/%d",
|
15
|
-
wday: {
|
16
|
-
Monday: "Mon",
|
17
|
-
Tuesday: "Tue",
|
18
|
-
Wednesday: "Wed",
|
19
|
-
Thursday: "Thu",
|
20
|
-
Friday: "Fri",
|
21
|
-
Saturday: "Sat",
|
22
|
-
Sunday: "Sun"
|
23
|
-
}
|
24
|
-
}
|
25
|
-
|
26
13
|
class Error < StandardError; end
|
27
14
|
class ParameterError < Error; end
|
28
15
|
class ConfigurationError < Error; end
|
data/pkg/.keep
ADDED
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goldman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wei Chen (willsmile)
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: goldman for generating option list of schedule
|
14
14
|
email:
|
@@ -26,6 +26,7 @@ files:
|
|
26
26
|
- Rakefile
|
27
27
|
- exe/goldman
|
28
28
|
- lib/goldman.rb
|
29
|
+
- lib/goldman/cli.rb
|
29
30
|
- lib/goldman/config.rb
|
30
31
|
- lib/goldman/date_range.rb
|
31
32
|
- lib/goldman/formatter.rb
|
@@ -33,6 +34,7 @@ files:
|
|
33
34
|
- lib/goldman/schedule_list.rb
|
34
35
|
- lib/goldman/version.rb
|
35
36
|
- lib/goldman/wday.rb
|
37
|
+
- pkg/.keep
|
36
38
|
homepage: https://github.com/willsmile/goldman-rb
|
37
39
|
licenses:
|
38
40
|
- MIT
|