flycal-cli 1.3 → 1.5.1
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/flycal +2 -0
- data/lib/flycal/cli/app.rb +0 -2
- data/lib/flycal/cli/auth.rb +8 -0
- data/lib/flycal/cli/config.rb +14 -0
- data/lib/flycal/cli/hooks.rb +76 -21
- data/lib/flycal.rb +1 -1
- data/lib/rubygems_plugin.rb +11 -0
- data/locales/en.json +4 -0
- data/locales/it.json +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d5920907ee209e0ea1204364f39bff454f52eb5214d4a2f72011b037cb6f6e58
|
|
4
|
+
data.tar.gz: e140b8f76c717c338d33b85f53b08defb9fde1aecfbdcf6e416ad33b2a87ed94
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 737242d48ae220aefad6560bf0a205ee83862b78ebedb479a2dc825da432a31516382fbea88681eede9bc66e61775b2e774f0508d2a6cb0b0e65469ebadbfd3f
|
|
7
|
+
data.tar.gz: b9aab68b6f14e0abb7d97ce3a975ee5be64ba3bc96a4263f8d7b01a1c24c121f4f46fce3913651a7cfeb83e7b7544698c1001724716abc8a86d1a7dc102bed70
|
data/bin/flycal
CHANGED
data/lib/flycal/cli/app.rb
CHANGED
|
@@ -30,7 +30,6 @@ module Cli
|
|
|
30
30
|
if Auth.logged_in?
|
|
31
31
|
puts Locale.t("login.already_connected")
|
|
32
32
|
Hooks.after_login
|
|
33
|
-
puts "\n#{Locale.t('login.next_config')}" unless Config.calendar_default
|
|
34
33
|
return
|
|
35
34
|
end
|
|
36
35
|
|
|
@@ -41,7 +40,6 @@ module Cli
|
|
|
41
40
|
Auth.login(mode)
|
|
42
41
|
puts "\n#{Locale.t('login.success')}"
|
|
43
42
|
Hooks.after_login
|
|
44
|
-
puts "\n#{Locale.t('login.next_config')}" unless Config.calendar_default
|
|
45
43
|
rescue Flycal::Error => e
|
|
46
44
|
puts "Error: #{e.message}"
|
|
47
45
|
exit 1
|
data/lib/flycal/cli/auth.rb
CHANGED
|
@@ -28,6 +28,8 @@ module Cli
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def logged_in?
|
|
31
|
+
return false unless tokens_present?
|
|
32
|
+
|
|
31
33
|
creds = credentials
|
|
32
34
|
return false unless creds
|
|
33
35
|
|
|
@@ -37,6 +39,12 @@ module Cli
|
|
|
37
39
|
false
|
|
38
40
|
end
|
|
39
41
|
|
|
42
|
+
# Google session file. config.yml is not a login signal (it survives uninstall).
|
|
43
|
+
def tokens_present?
|
|
44
|
+
path = Config.tokens_path
|
|
45
|
+
File.file?(path) && !File.size(path).to_i.zero?
|
|
46
|
+
end
|
|
47
|
+
|
|
40
48
|
def login(mode)
|
|
41
49
|
mode = normalize_mode(mode)
|
|
42
50
|
if Config.auth_client && Config.auth_client != mode && File.exist?(Config.tokens_path)
|
data/lib/flycal/cli/config.rb
CHANGED
|
@@ -8,6 +8,7 @@ module Cli
|
|
|
8
8
|
class Config
|
|
9
9
|
CONFIG_DIR = File.expand_path("~/.flycal")
|
|
10
10
|
CONFIG_FILE = File.join(CONFIG_DIR, "config.yml")
|
|
11
|
+
CONFIG_BACKUP_FILE = File.join(CONFIG_DIR, "config.backup.yml")
|
|
11
12
|
CREDENTIALS_FILE = File.join(CONFIG_DIR, "credentials.json")
|
|
12
13
|
TOKENS_FILE = File.join(CONFIG_DIR, "tokens.yml")
|
|
13
14
|
DEFAULTS_FILE = File.expand_path("../../../config/defaults.yml", __dir__)
|
|
@@ -162,6 +163,19 @@ module Cli
|
|
|
162
163
|
CONFIG_FILE
|
|
163
164
|
end
|
|
164
165
|
|
|
166
|
+
def config_backup_file
|
|
167
|
+
CONFIG_BACKUP_FILE
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def backup_and_remove_config!
|
|
171
|
+
source = config_file
|
|
172
|
+
return false unless File.file?(source)
|
|
173
|
+
|
|
174
|
+
FileUtils.mkdir_p(config_dir)
|
|
175
|
+
FileUtils.mv(source, config_backup_file)
|
|
176
|
+
true
|
|
177
|
+
end
|
|
178
|
+
|
|
165
179
|
def locale
|
|
166
180
|
load["locale"].to_s
|
|
167
181
|
end
|
data/lib/flycal/cli/hooks.rb
CHANGED
|
@@ -8,36 +8,50 @@ module Cli
|
|
|
8
8
|
def after_install
|
|
9
9
|
return if skip_post_install?
|
|
10
10
|
return unless interactive?
|
|
11
|
-
|
|
12
|
-
if Auth.logged_in?
|
|
13
|
-
after_login
|
|
14
|
-
return
|
|
15
|
-
end
|
|
11
|
+
return if Auth.logged_in?
|
|
16
12
|
|
|
17
13
|
puts "#{bold('flycal-cli')} #{Locale.t('hooks.after_install.ready')}"
|
|
18
14
|
print "#{Locale.t('hooks.after_install.prompt')} "
|
|
19
|
-
|
|
15
|
+
launch_login if accept_default_yes?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def after_uninstall
|
|
19
|
+
return if skip_post_uninstall?
|
|
20
|
+
return unless interactive?
|
|
21
|
+
return unless last_flycal_cli_install?
|
|
22
|
+
return unless File.file?(Config.config_file)
|
|
20
23
|
|
|
21
|
-
|
|
24
|
+
print "#{Locale.t('hooks.after_uninstall.prompt')} "
|
|
25
|
+
return unless accept_default_no?
|
|
26
|
+
|
|
27
|
+
if Config.backup_and_remove_config!
|
|
28
|
+
puts Locale.t("hooks.after_uninstall.saved", { backup: Config.config_backup_file })
|
|
29
|
+
end
|
|
22
30
|
end
|
|
23
31
|
|
|
24
32
|
def after_login
|
|
25
|
-
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
creds = Auth.credentials
|
|
34
|
+
return unless creds
|
|
35
|
+
|
|
36
|
+
selected = nil
|
|
37
|
+
begin
|
|
38
|
+
calendars = Flycal.connect(credentials: creds).list_calendars
|
|
39
|
+
current = Config.calendar_default.to_s.strip
|
|
40
|
+
if current.empty?
|
|
41
|
+
selected = calendars.find { |calendar| calendar.respond_to?(:primary) && calendar.primary } || calendars.first
|
|
42
|
+
Config.calendar_default = selected.id if selected
|
|
43
|
+
else
|
|
44
|
+
selected = calendars.find { |calendar| calendar.id.to_s == current } ||
|
|
45
|
+
calendars.find { |calendar| calendar.summary.to_s == current }
|
|
46
|
+
end
|
|
47
|
+
rescue StandardError => e
|
|
48
|
+
warn "flycal-cli after_login: #{e.message}"
|
|
49
|
+
end
|
|
31
50
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
name = primary.id if name.empty?
|
|
51
|
+
name = display_name(selected) || Config.calendar_default
|
|
52
|
+
return if name.to_s.strip.empty?
|
|
35
53
|
|
|
36
|
-
|
|
37
|
-
puts Locale.t("hooks.after_login.change")
|
|
38
|
-
puts Locale.t("hooks.after_login.goodbye")
|
|
39
|
-
rescue StandardError
|
|
40
|
-
nil
|
|
54
|
+
announce_default_calendar(name)
|
|
41
55
|
end
|
|
42
56
|
|
|
43
57
|
def launch_login
|
|
@@ -53,6 +67,24 @@ module Cli
|
|
|
53
67
|
ENV["FLYCAL_SKIP_POST_INSTALL"].to_s == "1"
|
|
54
68
|
end
|
|
55
69
|
|
|
70
|
+
def skip_post_uninstall?
|
|
71
|
+
ENV["FLYCAL_SKIP_POST_UNINSTALL"].to_s == "1"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def last_flycal_cli_install?
|
|
75
|
+
Gem::Specification.find_all_by_name("flycal-cli").size <= 1
|
|
76
|
+
rescue StandardError
|
|
77
|
+
true
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def skip_cli_after_install?(argv)
|
|
81
|
+
argv = Array(argv)
|
|
82
|
+
return true if argv.intersect?(%w[--version -v --help -h])
|
|
83
|
+
|
|
84
|
+
command = argv.find { |arg| !arg.start_with?("-") }
|
|
85
|
+
%w[login help].include?(command.to_s)
|
|
86
|
+
end
|
|
87
|
+
|
|
56
88
|
def interactive?
|
|
57
89
|
$stdin.tty? && $stdout.tty?
|
|
58
90
|
end
|
|
@@ -67,11 +99,34 @@ module Cli
|
|
|
67
99
|
%w[y yes].include?(answer)
|
|
68
100
|
end
|
|
69
101
|
|
|
102
|
+
def accept_default_no?(input = $stdin)
|
|
103
|
+
line = input.gets
|
|
104
|
+
return false if line.nil?
|
|
105
|
+
|
|
106
|
+
answer = line.strip.downcase
|
|
107
|
+
return false if answer.empty?
|
|
108
|
+
|
|
109
|
+
%w[y yes].include?(answer)
|
|
110
|
+
end
|
|
111
|
+
|
|
70
112
|
def bold(text)
|
|
71
113
|
return text.to_s unless $stdout.tty?
|
|
72
114
|
|
|
73
115
|
"\e[1m#{text}\e[0m"
|
|
74
116
|
end
|
|
117
|
+
|
|
118
|
+
def announce_default_calendar(name)
|
|
119
|
+
puts "#{bold('flycal-cli')} #{Locale.t('hooks.after_login.using', { calendar: bold(name) })}"
|
|
120
|
+
puts Locale.t("hooks.after_login.change")
|
|
121
|
+
puts Locale.t("hooks.after_login.goodbye")
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def display_name(calendar)
|
|
125
|
+
return nil unless calendar
|
|
126
|
+
|
|
127
|
+
name = calendar.summary.to_s.strip
|
|
128
|
+
name.empty? ? calendar.id.to_s : name
|
|
129
|
+
end
|
|
75
130
|
end
|
|
76
131
|
end
|
|
77
132
|
end
|
data/lib/flycal.rb
CHANGED
data/lib/rubygems_plugin.rb
CHANGED
|
@@ -11,3 +11,14 @@ Gem.post_install do |installer|
|
|
|
11
11
|
warn "flycal-cli post-install: #{e.message}"
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
|
+
|
|
15
|
+
Gem.pre_uninstall do |uninstaller|
|
|
16
|
+
next unless uninstaller.spec.name == "flycal-cli"
|
|
17
|
+
|
|
18
|
+
begin
|
|
19
|
+
require "flycal_cli"
|
|
20
|
+
Flycal::Cli::Hooks.after_uninstall
|
|
21
|
+
rescue LoadError, StandardError => e
|
|
22
|
+
warn "flycal-cli pre-uninstall: #{e.message}"
|
|
23
|
+
end
|
|
24
|
+
end
|
data/locales/en.json
CHANGED
|
@@ -61,6 +61,10 @@
|
|
|
61
61
|
"using": "is using %{calendar} by default,",
|
|
62
62
|
"change": "you can change it using command 'flycal config',",
|
|
63
63
|
"goodbye": "happy calendling!"
|
|
64
|
+
},
|
|
65
|
+
"after_uninstall": {
|
|
66
|
+
"prompt": "Remove ~/.flycal/config.yml? It will be saved as config.backup.yml (y/N):",
|
|
67
|
+
"saved": "Saved as %{backup}"
|
|
64
68
|
}
|
|
65
69
|
},
|
|
66
70
|
"errors": {
|
data/locales/it.json
CHANGED
|
@@ -61,6 +61,10 @@
|
|
|
61
61
|
"using": "sta usando %{calendar} come predefinito,",
|
|
62
62
|
"change": "puoi cambiarlo con il comando 'flycal config',",
|
|
63
63
|
"goodbye": "happy calendling!"
|
|
64
|
+
},
|
|
65
|
+
"after_uninstall": {
|
|
66
|
+
"prompt": "Vuoi rimuovere ~/.flycal/config.yml? Verrà salvato come config.backup.yml (y/N):",
|
|
67
|
+
"saved": "Salvato in %{backup}"
|
|
64
68
|
}
|
|
65
69
|
},
|
|
66
70
|
"errors": {
|