flycal-cli 1.3 → 1.4
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/config.rb +10 -0
- data/lib/flycal/cli/hooks.rb +44 -14
- data/lib/flycal.rb +1 -1
- 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: d7f3ae70fd1c2b1259a400d7bea2ff5b936765ea3c4031e35d11ab59e755bd98
|
|
4
|
+
data.tar.gz: e9decf6f9520e826f010e7c5dd8f9fe4f2cd5739c079b0ffa133fdebcd721cf4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 13cc3c1b5c9aaa8e4b630920e6752a61a0bdd90de2a6d302473bbe75c548566b6ab5438f5c9d86180c4a11d424a902069aa3f8e1b6e0f948e0bacb1292a495ac
|
|
7
|
+
data.tar.gz: 3d0a56c6403f673b7b8fcf4e06797970e936b3448e2496a22ee2072dc07efed566ece48ad98e42132371f8bae6b8d2143a6915ec281b9e9d0fe0f647db47e7ea
|
data/bin/flycal
CHANGED
data/lib/flycal/cli/config.rb
CHANGED
|
@@ -45,6 +45,16 @@ module Cli
|
|
|
45
45
|
save(data)
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
+
def after_install_done?
|
|
49
|
+
load["after_install_done"] == true
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def after_install_done=(value)
|
|
53
|
+
data = load
|
|
54
|
+
data["after_install_done"] = value ? true : false
|
|
55
|
+
save(data)
|
|
56
|
+
end
|
|
57
|
+
|
|
48
58
|
def credentials_path
|
|
49
59
|
CREDENTIALS_FILE
|
|
50
60
|
end
|
data/lib/flycal/cli/hooks.rb
CHANGED
|
@@ -8,36 +8,45 @@ module Cli
|
|
|
8
8
|
def after_install
|
|
9
9
|
return if skip_post_install?
|
|
10
10
|
return unless interactive?
|
|
11
|
+
return if Config.after_install_done?
|
|
11
12
|
|
|
12
13
|
if Auth.logged_in?
|
|
13
14
|
after_login
|
|
15
|
+
Config.after_install_done = true
|
|
14
16
|
return
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
puts "#{bold('flycal-cli')} #{Locale.t('hooks.after_install.ready')}"
|
|
18
20
|
print "#{Locale.t('hooks.after_install.prompt')} "
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
launch_login
|
|
21
|
+
accepted = accept_default_yes?
|
|
22
|
+
Config.after_install_done = true
|
|
23
|
+
launch_login if accepted
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
def after_login
|
|
25
27
|
return unless Auth.logged_in?
|
|
26
|
-
return if Config.calendar_default
|
|
27
28
|
|
|
29
|
+
current = Config.calendar_default.to_s.strip
|
|
28
30
|
calendars = Flycal.connect(credentials: Auth.credentials).list_calendars
|
|
29
|
-
primary = calendars.find { |calendar| calendar.respond_to?(:primary) && calendar.primary } || calendars.first
|
|
30
|
-
return unless primary
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
if current.empty?
|
|
33
|
+
selected = calendars.find { |calendar| calendar.respond_to?(:primary) && calendar.primary } || calendars.first
|
|
34
|
+
return unless selected
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
Config.calendar_default = selected.id
|
|
37
|
+
announce_default_calendar(display_name(selected))
|
|
38
|
+
else
|
|
39
|
+
selected = calendars.find { |calendar| calendar.id.to_s == current } ||
|
|
40
|
+
calendars.find { |calendar| calendar.summary.to_s == current }
|
|
41
|
+
announce_default_calendar(display_name(selected) || current)
|
|
42
|
+
end
|
|
43
|
+
rescue StandardError => e
|
|
44
|
+
fallback = Config.calendar_default.to_s.strip
|
|
45
|
+
if fallback.empty?
|
|
46
|
+
warn "flycal-cli after_login: #{e.message}"
|
|
47
|
+
else
|
|
48
|
+
announce_default_calendar(fallback)
|
|
49
|
+
end
|
|
41
50
|
end
|
|
42
51
|
|
|
43
52
|
def launch_login
|
|
@@ -53,6 +62,14 @@ module Cli
|
|
|
53
62
|
ENV["FLYCAL_SKIP_POST_INSTALL"].to_s == "1"
|
|
54
63
|
end
|
|
55
64
|
|
|
65
|
+
def skip_cli_after_install?(argv)
|
|
66
|
+
argv = Array(argv)
|
|
67
|
+
return true if argv.intersect?(%w[--version -v --help -h])
|
|
68
|
+
|
|
69
|
+
command = argv.find { |arg| !arg.start_with?("-") }
|
|
70
|
+
%w[login help].include?(command.to_s)
|
|
71
|
+
end
|
|
72
|
+
|
|
56
73
|
def interactive?
|
|
57
74
|
$stdin.tty? && $stdout.tty?
|
|
58
75
|
end
|
|
@@ -72,6 +89,19 @@ module Cli
|
|
|
72
89
|
|
|
73
90
|
"\e[1m#{text}\e[0m"
|
|
74
91
|
end
|
|
92
|
+
|
|
93
|
+
def announce_default_calendar(name)
|
|
94
|
+
puts "#{bold('flycal-cli')} #{Locale.t('hooks.after_login.using', { calendar: bold(name) })}"
|
|
95
|
+
puts Locale.t("hooks.after_login.change")
|
|
96
|
+
puts Locale.t("hooks.after_login.goodbye")
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def display_name(calendar)
|
|
100
|
+
return nil unless calendar
|
|
101
|
+
|
|
102
|
+
name = calendar.summary.to_s.strip
|
|
103
|
+
name.empty? ? calendar.id.to_s : name
|
|
104
|
+
end
|
|
75
105
|
end
|
|
76
106
|
end
|
|
77
107
|
end
|
data/lib/flycal.rb
CHANGED