runby_pace 0.61.155 → 0.61.156
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 +4 -4
- data/bin/runbypace +2 -2
- data/lib/runby_pace/cli/cli.rb +127 -0
- data/lib/runby_pace/cli/config.rb +82 -0
- data/lib/runby_pace.rb +1 -0
- metadata +5 -4
- data/lib/runby_pace/cli.rb +0 -57
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6f97923bb6c2c8726a14a7218d9c93350099f2a8
|
|
4
|
+
data.tar.gz: 3f086c6bf1d291f552d8cc7a1c08a1991dfcbfb1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e79168f22807655d7d1d63daed5c2adabd62a44952c3ddde82b069e2f633fdd1c508f95d57b82656fb93b4ad1bcf9d3d831aa7256182a1f07df7ad660b53d2c4
|
|
7
|
+
data.tar.gz: 4179fb47ff8d3e1febe646997d35fb23537c9ae78a2968d70df340174c50354ae86f1fd28029b2efbad485b0fe4aae275c1fc3fffb5525c4da5d0c75daf5bb5f
|
data/bin/runbypace
CHANGED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'readline'
|
|
4
|
+
require 'optparse'
|
|
5
|
+
require_relative 'config'
|
|
6
|
+
|
|
7
|
+
module Runby
|
|
8
|
+
module Cli
|
|
9
|
+
# Command line interface and REPL for RunbyPace
|
|
10
|
+
class Cli
|
|
11
|
+
def initialize(args = ARGV)
|
|
12
|
+
@args = args
|
|
13
|
+
@config = Config.new
|
|
14
|
+
@options = parse_options args
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def run
|
|
18
|
+
puts 'Runby Pace REPL!'
|
|
19
|
+
bnd = binding
|
|
20
|
+
while (input = Readline.readline('🏃 ', true))
|
|
21
|
+
begin
|
|
22
|
+
result = bnd.eval input
|
|
23
|
+
rescue StandardError => e
|
|
24
|
+
puts "#{e.class}: #{e.message}"
|
|
25
|
+
else
|
|
26
|
+
puts result
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def print_targets(five_k_time, distance_units = :mi)
|
|
32
|
+
five_k_time = @config['five_k_time'] if five_k_time.nil?
|
|
33
|
+
|
|
34
|
+
five_k_time = Runby.sanitize(five_k_time).as(RunbyTime)
|
|
35
|
+
puts "\nIf you can run a 5K in #{five_k_time}, your training paces should be:"
|
|
36
|
+
paces = []
|
|
37
|
+
RunTypes.all_classes.each do |run_type|
|
|
38
|
+
run = run_type.new
|
|
39
|
+
paces.push(description: run.description, pace: run.lookup_pace(five_k_time, distance_units))
|
|
40
|
+
end
|
|
41
|
+
paces.sort_by { |p| p[:pace].fast }.reverse_each { |p| puts " #{p[:description]}: #{p[:pace]}" }
|
|
42
|
+
nil
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# -- Shortcuts for the REPL
|
|
46
|
+
def di(*args)
|
|
47
|
+
Distance.new(*args)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def du(*args)
|
|
51
|
+
DistanceUnit.new(*args)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def pc(*args)
|
|
55
|
+
Pace.new(*args)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def sp(*args)
|
|
59
|
+
Speed.new(*args)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def tm(*args)
|
|
63
|
+
RunbyTime.new(*args)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
def parse_options(options)
|
|
69
|
+
args = { targets: nil }
|
|
70
|
+
|
|
71
|
+
OptionParser.new do |opts|
|
|
72
|
+
opts.banner = 'Usage: runbypace.rb [options]'
|
|
73
|
+
|
|
74
|
+
opts.on('-h', '--help', 'Display this help message') do
|
|
75
|
+
puts opts
|
|
76
|
+
exit
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
opts.on('-c', '--config [SETTING][=NEW_VALUE]', 'Get or set a configuration value') do |config|
|
|
80
|
+
manage_config config
|
|
81
|
+
exit
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
opts.on('-t', '--targets [5K race time]', 'Show target paces') do |targets|
|
|
85
|
+
args[:targets] = targets
|
|
86
|
+
print_targets targets
|
|
87
|
+
exit
|
|
88
|
+
end
|
|
89
|
+
end.parse!(options)
|
|
90
|
+
args
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def manage_config(config)
|
|
94
|
+
c = parse_config_setting config
|
|
95
|
+
unless c.key
|
|
96
|
+
# No key specified. Print all settings.
|
|
97
|
+
@config.pretty_print
|
|
98
|
+
return
|
|
99
|
+
end
|
|
100
|
+
if c.value
|
|
101
|
+
# Set setting "key" to new "value"
|
|
102
|
+
@config[c.key] = c.value
|
|
103
|
+
return
|
|
104
|
+
end
|
|
105
|
+
if c.clear_setting
|
|
106
|
+
@config[c.key] = nil
|
|
107
|
+
else
|
|
108
|
+
# Print the value of setting "key"
|
|
109
|
+
p @config[c.key]
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def parse_config_setting(setting)
|
|
114
|
+
setting = '' if setting.nil?
|
|
115
|
+
Class.new do
|
|
116
|
+
attr_reader :key, :value, :clear_setting
|
|
117
|
+
def initialize(setting)
|
|
118
|
+
tokens = setting.split('=')
|
|
119
|
+
@key = tokens[0]
|
|
120
|
+
@value = tokens[1]
|
|
121
|
+
@clear_setting = (@value.nil? && setting.include?('='))
|
|
122
|
+
end
|
|
123
|
+
end.new(setting)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'yaml'
|
|
4
|
+
require 'pp'
|
|
5
|
+
|
|
6
|
+
module Runby
|
|
7
|
+
#
|
|
8
|
+
module Cli
|
|
9
|
+
class Config
|
|
10
|
+
USER_CONFIG_PATH = File.expand_path('~/.runbypace').freeze
|
|
11
|
+
|
|
12
|
+
VALID_OPTIONS = {
|
|
13
|
+
five_k_time: { validate_as: RunbyTime }
|
|
14
|
+
}.freeze
|
|
15
|
+
|
|
16
|
+
def initialize
|
|
17
|
+
@settings = load_user_settings
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def load_user_settings
|
|
21
|
+
if File.exist? USER_CONFIG_PATH
|
|
22
|
+
YAML.load_file USER_CONFIG_PATH
|
|
23
|
+
else
|
|
24
|
+
{}
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def store_user_settings
|
|
29
|
+
File.open(USER_CONFIG_PATH, 'w') { |file| file.write @settings.to_yaml }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def [](key)
|
|
33
|
+
return unless known_setting?(key)
|
|
34
|
+
return unless option_configured?(key)
|
|
35
|
+
"#{key} => #{@settings[key]}"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def []=(key, value)
|
|
39
|
+
return unless known_setting?(key)
|
|
40
|
+
if value
|
|
41
|
+
value = sanitize_value key, value
|
|
42
|
+
return unless value
|
|
43
|
+
@settings[key] = value.to_s
|
|
44
|
+
else
|
|
45
|
+
@settings.delete(key)
|
|
46
|
+
end
|
|
47
|
+
store_user_settings
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def pretty_print
|
|
51
|
+
pp @settings
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def known_setting?(key)
|
|
55
|
+
unless VALID_OPTIONS.key?(key.to_sym)
|
|
56
|
+
puts "Unknown setting #{key}"
|
|
57
|
+
return false
|
|
58
|
+
end
|
|
59
|
+
true
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def sanitize_value(key, value)
|
|
63
|
+
cls = VALID_OPTIONS[key.to_sym][:validate_as]
|
|
64
|
+
begin
|
|
65
|
+
value = Runby.sanitize(value).as(cls)
|
|
66
|
+
rescue StandardError => ex
|
|
67
|
+
value = nil
|
|
68
|
+
p ex.message
|
|
69
|
+
end
|
|
70
|
+
value
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def option_configured?(key)
|
|
74
|
+
unless @settings.key? key
|
|
75
|
+
puts "#{key} not configured. Set with:\n\trunbypace --config #{key} VALUE"
|
|
76
|
+
false
|
|
77
|
+
end
|
|
78
|
+
true
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
data/lib/runby_pace.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
require 'runby_pace/version'
|
|
3
3
|
Dir[File.dirname(__FILE__) + '/runby_pace/*.rb'].each { |file| require file }
|
|
4
|
+
Dir[File.dirname(__FILE__) + '/runby_pace/cli/*.rb'].each { |file| require file }
|
|
4
5
|
Dir[File.dirname(__FILE__) + '/runby_pace/run_types/*.rb'].each { |file| require file }
|
|
5
6
|
Dir[File.dirname(__FILE__) + '/runby_pace/utility/*.rb'].each { |file| require file }
|
|
6
7
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: runby_pace
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.61.
|
|
4
|
+
version: 0.61.156
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ty Walls
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-07-
|
|
11
|
+
date: 2017-07-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -74,7 +74,8 @@ files:
|
|
|
74
74
|
- bin/runbypace
|
|
75
75
|
- bin/setup
|
|
76
76
|
- lib/runby_pace.rb
|
|
77
|
-
- lib/runby_pace/cli.rb
|
|
77
|
+
- lib/runby_pace/cli/cli.rb
|
|
78
|
+
- lib/runby_pace/cli/config.rb
|
|
78
79
|
- lib/runby_pace/distance.rb
|
|
79
80
|
- lib/runby_pace/distance_unit.rb
|
|
80
81
|
- lib/runby_pace/golden_pace_set.rb
|
|
@@ -108,7 +109,7 @@ homepage: https://github.com/tygerbytes/runby-pace
|
|
|
108
109
|
licenses:
|
|
109
110
|
- MIT
|
|
110
111
|
metadata:
|
|
111
|
-
commit-hash:
|
|
112
|
+
commit-hash: 8c0727f6450d43e4fcd00e44901c183622aa9062
|
|
112
113
|
post_install_message:
|
|
113
114
|
rdoc_options: []
|
|
114
115
|
require_paths:
|
data/lib/runby_pace/cli.rb
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'readline'
|
|
4
|
-
|
|
5
|
-
module Runby
|
|
6
|
-
# Command line interface and REPL for RunbyPace
|
|
7
|
-
class Cli
|
|
8
|
-
def initialize(args = ARGV)
|
|
9
|
-
@args = args
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def run
|
|
13
|
-
puts 'Runby Pace REPL!'
|
|
14
|
-
bnd = binding
|
|
15
|
-
while (input = Readline.readline('🏃 ', true))
|
|
16
|
-
begin
|
|
17
|
-
result = bnd.eval input
|
|
18
|
-
rescue StandardError => e
|
|
19
|
-
puts "#{e.class}: #{e.message}"
|
|
20
|
-
else
|
|
21
|
-
puts result
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def targets(five_k_time, distance_units = :mi)
|
|
27
|
-
five_k_time = Runby.sanitize(five_k_time).as(RunbyTime)
|
|
28
|
-
puts "\nIf you can run a 5K in #{five_k_time}, your training paces should be:"
|
|
29
|
-
RunTypes.all_classes.each do |run_type|
|
|
30
|
-
run = run_type.new
|
|
31
|
-
puts " #{run.description}: #{run.lookup_pace(five_k_time, distance_units)}"
|
|
32
|
-
end
|
|
33
|
-
nil
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# -- Shortcuts
|
|
37
|
-
def d(*args)
|
|
38
|
-
Distance.new(*args)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def du(*args)
|
|
42
|
-
DistanceUnit.new(*args)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def p(*args)
|
|
46
|
-
Pace.new(*args)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def s(*args)
|
|
50
|
-
Speed.new(*args)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def t(*args)
|
|
54
|
-
RunbyTime.new(*args)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|