flycal-cli 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2558d06aa185f1411911ac5a8e9611cf1b5ae1d2ce0ce7d3b4af4b99d6b25fb9
4
- data.tar.gz: a04a4a24dd01325844b35593d487e7cfa671d2c49a7cc164944854f1e7b7f1f3
3
+ metadata.gz: d7f3ae70fd1c2b1259a400d7bea2ff5b936765ea3c4031e35d11ab59e755bd98
4
+ data.tar.gz: e9decf6f9520e826f010e7c5dd8f9fe4f2cd5739c079b0ffa133fdebcd721cf4
5
5
  SHA512:
6
- metadata.gz: a7311ac6ce8d80c2cdb0ea1b9749f91750597b1260ae6cf2e5ce9bfe42271eefdbcf485d2603581cf203cd89a96eb879273cde3001a76ab3c15d0b73016d44f4
7
- data.tar.gz: d1283b663c5a6f280af567c90bf61b25968014df5d603a1c12fc3395c04e41766daf77d7fdfc8509c4795bdb493c4144c773922a78e63df9121934f3bb0eec2d
6
+ metadata.gz: 13cc3c1b5c9aaa8e4b630920e6752a61a0bdd90de2a6d302473bbe75c548566b6ab5438f5c9d86180c4a11d424a902069aa3f8e1b6e0f948e0bacb1292a495ac
7
+ data.tar.gz: 3d0a56c6403f673b7b8fcf4e06797970e936b3448e2496a22ee2072dc07efed566ece48ad98e42132371f8bae6b8d2143a6915ec281b9e9d0fe0f647db47e7ea
data/bin/flycal CHANGED
@@ -8,4 +8,6 @@ if ARGV.include?("--version") || ARGV.include?("-v")
8
8
  exit 0
9
9
  end
10
10
 
11
+ Flycal::Cli::Hooks.after_install unless Flycal::Cli::Hooks.skip_cli_after_install?(ARGV)
12
+
11
13
  Flycal::Cli::App.start(ARGV)
@@ -29,7 +29,8 @@ module Cli
29
29
  apply_locale_override
30
30
  if Auth.logged_in?
31
31
  puts Locale.t("login.already_connected")
32
- puts "\n#{Locale.t('login.next_config')}"
32
+ Hooks.after_login
33
+ puts "\n#{Locale.t('login.next_config')}" unless Config.calendar_default
33
34
  return
34
35
  end
35
36
 
@@ -39,7 +40,8 @@ module Cli
39
40
  begin
40
41
  Auth.login(mode)
41
42
  puts "\n#{Locale.t('login.success')}"
42
- puts "\n#{Locale.t('login.next_config')}"
43
+ Hooks.after_login
44
+ puts "\n#{Locale.t('login.next_config')}" unless Config.calendar_default
43
45
  rescue Flycal::Error => e
44
46
  puts "Error: #{e.message}"
45
47
  exit 1
@@ -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
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flycal
4
+ module Cli
5
+ # Post-install / post-login onboarding.
6
+ class Hooks
7
+ class << self
8
+ def after_install
9
+ return if skip_post_install?
10
+ return unless interactive?
11
+ return if Config.after_install_done?
12
+
13
+ if Auth.logged_in?
14
+ after_login
15
+ Config.after_install_done = true
16
+ return
17
+ end
18
+
19
+ puts "#{bold('flycal-cli')} #{Locale.t('hooks.after_install.ready')}"
20
+ print "#{Locale.t('hooks.after_install.prompt')} "
21
+ accepted = accept_default_yes?
22
+ Config.after_install_done = true
23
+ launch_login if accepted
24
+ end
25
+
26
+ def after_login
27
+ return unless Auth.logged_in?
28
+
29
+ current = Config.calendar_default.to_s.strip
30
+ calendars = Flycal.connect(credentials: Auth.credentials).list_calendars
31
+
32
+ if current.empty?
33
+ selected = calendars.find { |calendar| calendar.respond_to?(:primary) && calendar.primary } || calendars.first
34
+ return unless selected
35
+
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
50
+ end
51
+
52
+ def launch_login
53
+ bin = begin
54
+ Gem.bin_path("flycal-cli", "flycal")
55
+ rescue Gem::Exception
56
+ "flycal"
57
+ end
58
+ system(bin, "login")
59
+ end
60
+
61
+ def skip_post_install?
62
+ ENV["FLYCAL_SKIP_POST_INSTALL"].to_s == "1"
63
+ end
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
+
73
+ def interactive?
74
+ $stdin.tty? && $stdout.tty?
75
+ end
76
+
77
+ def accept_default_yes?(input = $stdin)
78
+ line = input.gets
79
+ return true if line.nil?
80
+
81
+ answer = line.strip.downcase
82
+ return true if answer.empty?
83
+
84
+ %w[y yes].include?(answer)
85
+ end
86
+
87
+ def bold(text)
88
+ return text.to_s unless $stdout.tty?
89
+
90
+ "\e[1m#{text}\e[0m"
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
105
+ end
106
+ end
107
+ end
108
+ end
data/lib/flycal/cli.rb CHANGED
@@ -6,6 +6,7 @@ require "flycal/cli/file_cache"
6
6
  require "flycal/cli/locale"
7
7
  require "flycal/cli/auth"
8
8
  require "flycal/cli/clipboard"
9
+ require "flycal/cli/hooks"
9
10
  require "flycal/cli/app"
10
11
 
11
12
  module Flycal
data/lib/flycal.rb CHANGED
@@ -4,7 +4,7 @@
4
4
  # Under Rails, Zeitwerk autoloads lib/flycal/*.
5
5
  # The CLI gem entrypoint (flycal_cli/lib/flycal_cli.rb) eager-requires what it needs.
6
6
  module Flycal
7
- VERSION = "1.2.3"
7
+ VERSION = "1.4"
8
8
 
9
9
  def self.connect(credentials:)
10
10
  Client.new(credentials: credentials)
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Loaded automatically by RubyGems. Keep this file tiny; work happens in the hook.
4
+ Gem.post_install do |installer|
5
+ next unless installer.spec.name == "flycal-cli"
6
+
7
+ begin
8
+ require "flycal_cli"
9
+ Flycal::Cli::Hooks.after_install
10
+ rescue LoadError, StandardError => e
11
+ warn "flycal-cli post-install: #{e.message}"
12
+ end
13
+ end
data/locales/en.json CHANGED
@@ -52,6 +52,17 @@
52
52
  "header": "found %{count} slots\nfrom %{from} to %{to}\nwith duration %{duration}, template %{template}\nconsidering calendars",
53
53
  "copied_to_clipboard": "✓ Slot list copied to clipboard (%{tool})"
54
54
  },
55
+ "hooks": {
56
+ "after_install": {
57
+ "ready": "is setup correctly,",
58
+ "prompt": "Let's login w/ Google to start using it (Y/n):"
59
+ },
60
+ "after_login": {
61
+ "using": "is using %{calendar} by default,",
62
+ "change": "you can change it using command 'flycal config',",
63
+ "goodbye": "happy calendling!"
64
+ }
65
+ },
55
66
  "errors": {
56
67
  "not_connected": "You are not connected. Run 'flycal login' first.",
57
68
  "duration_positive": "Error: --in must be a positive duration.",
data/locales/it.json CHANGED
@@ -52,6 +52,17 @@
52
52
  "header": "trovati %{count} slot\nda %{from} a %{to}\ncon durata %{duration}, template %{template}\nconsiderando i calendari",
53
53
  "copied_to_clipboard": "✓ Lista slot copiata negli appunti (%{tool})"
54
54
  },
55
+ "hooks": {
56
+ "after_install": {
57
+ "ready": "è installato correttamente,",
58
+ "prompt": "Accedi con Google per iniziare a usarlo (Y/n):"
59
+ },
60
+ "after_login": {
61
+ "using": "sta usando %{calendar} come predefinito,",
62
+ "change": "puoi cambiarlo con il comando 'flycal config',",
63
+ "goodbye": "happy calendling!"
64
+ }
65
+ },
55
66
  "errors": {
56
67
  "not_connected": "Non sei connesso. Esegui prima 'flycal login'.",
57
68
  "duration_positive": "Errore: --in deve essere una durata positiva.",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flycal-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: '1.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - flycal-cli
@@ -146,6 +146,7 @@ files:
146
146
  - lib/flycal/cli/clipboard.rb
147
147
  - lib/flycal/cli/config.rb
148
148
  - lib/flycal/cli/file_cache.rb
149
+ - lib/flycal/cli/hooks.rb
149
150
  - lib/flycal/cli/locale.rb
150
151
  - lib/flycal/client.rb
151
152
  - lib/flycal/credentials.rb
@@ -176,6 +177,7 @@ files:
176
177
  - lib/flycal/time_format.rb
177
178
  - lib/flycal/version.rb
178
179
  - lib/flycal_cli.rb
180
+ - lib/rubygems_plugin.rb
179
181
  - locales/en.json
180
182
  - locales/it.json
181
183
  - mcp/README.md