-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.rb
executable file
·59 lines (41 loc) · 1.25 KB
/
run.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative 'lib/plurkapi'
require_relative 'lib/plurker'
require 'optparse'
DEFAULT_TOKEN_FILE = '~/.gmplurk.token'
DEFAULT_CONF_FILE = '~/.gmplurk.yml'
def parse_cmdline
options = {}
options[:force_login] = false
options[:token_file] = DEFAULT_TOKEN_FILE
options[:conf_file] = DEFAULT_CONF_FILE
optp = OptionParser.new
optp.banner = "Usage: #{$PROGRAM_NAME} [options]"
optp.separator <<~ENDS
Post good morning, good afternoon, etc, to Plurk depending on time of day.
ENDS
optp.on('-h', '-?', '--help', 'Option help') {
puts optp
exit
}
optp.on('-l', '--login', 'Ignore saved token and force a new login') {
options[:force_login] = true
}
optp.on('--token-file=FILENAME', "Set name of token file. Default: #{DEFAULT_TOKEN_FILE}") { |fname|
options[:token_file] = fname
}
optp.on('--conf-file=FILENAME', "Set name of config file. Default: #{DEFAULT_CONF_FILE}") { |fname|
options[:conf_file] = fname
}
optp.parse!
options
end
options = parse_cmdline
client = PlurkAPI.new(
force_login: options[:force_login],
token_file: options[:token_file],
conf_file: options[:conf_file]
)
Plurker.new(conf_file: options[:conf_file]).do_plurk(client)
__END__