From b1f073ad9934a945a4b9c20b70a942720c2a5638 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Tue, 23 Jul 2024 11:16:55 +0200 Subject: [PATCH] Remove --offline-only flag --- cmd/heartbeat/heartbeat.go | 2 -- cmd/offline/offline.go | 4 +-- cmd/params/params.go | 5 +--- cmd/params/params_test.go | 2 +- cmd/root.go | 1 - cmd/run.go | 6 ---- main_test.go | 56 -------------------------------------- 7 files changed, 4 insertions(+), 72 deletions(-) diff --git a/cmd/heartbeat/heartbeat.go b/cmd/heartbeat/heartbeat.go index 6bde717d..ef8847b7 100644 --- a/cmd/heartbeat/heartbeat.go +++ b/cmd/heartbeat/heartbeat.go @@ -105,8 +105,6 @@ func SendHeartbeats(v *viper.Viper, queueFilepath string) error { } handleOpts = append(handleOpts, offline.WithQueue(queueFilepath)) - } else if params.Offline.OfflineOnly { - return errors.New("--offline-only can NOT be used with --disable-offline") } handleOpts = append(handleOpts, backoff.WithBackoff(backoff.Config{ diff --git a/cmd/offline/offline.go b/cmd/offline/offline.go index 8de134ee..d84ec422 100644 --- a/cmd/offline/offline.go +++ b/cmd/offline/offline.go @@ -19,8 +19,8 @@ import ( ) // SaveHeartbeats saves heartbeats to the offline db without trying to send to the API. -// Used when we have more heartbeats than `offline.SendLimit`, when --offline-only enabled, -// when we couldn't send heartbeats to the API, or the API returned an auth error. +// Used when we have more heartbeats than `offline.SendLimit`, when we couldn't send +// heartbeats to the API, or the API returned an auth error. func SaveHeartbeats(v *viper.Viper, heartbeats []heartbeat.Heartbeat, queueFilepath string) error { params, err := loadParams(v) if err != nil { diff --git a/cmd/params/params.go b/cmd/params/params.go index f01dde0f..eea875f8 100644 --- a/cmd/params/params.go +++ b/cmd/params/params.go @@ -131,7 +131,6 @@ type ( // Offline contains offline related parameters. Offline struct { Disabled bool - OfflineOnly bool PrintMax int QueueFile string QueueFileLegacy string @@ -657,7 +656,6 @@ func LoadOfflineParams(v *viper.Viper) Offline { return Offline{ Disabled: disabled, - OfflineOnly: v.GetBool("offline-only"), PrintMax: v.GetInt("print-offline-heartbeats"), QueueFile: vipertools.GetString(v, "offline-queue-file"), QueueFileLegacy: vipertools.GetString(v, "offline-queue-file-legacy"), @@ -1041,9 +1039,8 @@ func (p Heartbeat) String() string { // String implements fmt.Stringer interface. func (p Offline) String() string { return fmt.Sprintf( - "disabled: %t, offline only: %t, print max: %d, queue file: '%s', queue file legacy: '%s', num sync max: %d", + "disabled: %t, print max: %d, queue file: '%s', queue file legacy: '%s', num sync max: %d", p.Disabled, - p.OfflineOnly, p.PrintMax, p.QueueFile, p.QueueFileLegacy, diff --git a/cmd/params/params_test.go b/cmd/params/params_test.go index 55b07080..a7286bc4 100644 --- a/cmd/params/params_test.go +++ b/cmd/params/params_test.go @@ -2505,7 +2505,7 @@ func TestOffline_String(t *testing.T) { assert.Equal( t, - "disabled: true, offline only: false, print max: 6, queue file: '/path/to/queue.file',"+ + "disabled: true, print max: 6, queue file: '/path/to/queue.file',"+ " queue file legacy: '/path/to/legacy.file', num sync max: 12", offline.String(), ) diff --git a/cmd/root.go b/cmd/root.go index bb683964..c0dc86f3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -245,7 +245,6 @@ func setFlags(cmd *cobra.Command, v *viper.Viper) { " new heartbeats.", offline.SyncMaxDefault), ) flags.Bool("offline-count", false, "Prints the number of heartbeats in the offline db, then exits.") - flags.Bool("offline-only", false, "Saves the heartbeat(s) to the offline db, then exits.") flags.Int( "timeout", api.DefaultTimeoutSecs, diff --git a/cmd/run.go b/cmd/run.go index eb15e6d3..25811c73 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -132,12 +132,6 @@ func RunE(cmd *cobra.Command, v *viper.Viper) error { if v.IsSet("entity") { log.Debugln("command: heartbeat") - if v.GetBool("offline-only") { - exitCode := saveHeartbeats(v) - - os.Exit(exitCode) // nolint:gocritic - } - return RunCmdWithOfflineSync(v, logFileParams.Verbose, logFileParams.SendDiagsOnErrors, cmdheartbeat.Run) } diff --git a/main_test.go b/main_test.go index ab93df32..422c8a2c 100644 --- a/main_test.go +++ b/main_test.go @@ -460,62 +460,6 @@ func TestSendHeartbeats_ExtraHeartbeats_SyncLegacyOfflineActivity(t *testing.T) assert.Eventually(t, func() bool { return numCalls == 4 }, time.Second, 50*time.Millisecond) } -func TestSendHeartbeats_OfflineOnly(t *testing.T) { - apiURL, router, close := setupTestServer() - defer close() - - router.HandleFunc("/users/current/heartbeats.bulk", func(_ http.ResponseWriter, _ *http.Request) { - require.FailNow(t, "Should not make any API request") - }) - - tmpDir := t.TempDir() - - offlineQueueFile, err := os.CreateTemp(tmpDir, "") - require.NoError(t, err) - - defer offlineQueueFile.Close() - - tmpConfigFile, err := os.CreateTemp(tmpDir, "wakatime.cfg") - require.NoError(t, err) - - defer tmpConfigFile.Close() - - tmpInternalConfigFile, err := os.CreateTemp(tmpDir, "wakatime-internal.cfg") - require.NoError(t, err) - - defer tmpInternalConfigFile.Close() - - data, err := os.ReadFile("testdata/extra_heartbeats.json") - require.NoError(t, err) - - buffer := bytes.NewBuffer(data) - - runWakatimeCli( - t, - buffer, - "--api-url", apiURL, - "--key", "00000000-0000-4000-8000-000000000000", - "--config", tmpConfigFile.Name(), - "--internal-config", tmpInternalConfigFile.Name(), - "--entity", "testdata/main.go", - "--extra-heartbeats", "true", - "--cursorpos", "100", - "--offline-queue-file", offlineQueueFile.Name(), - "--offline-only", - "--lineno", "42", - "--lines-in-file", "100", - "--time", "1585598059", - "--hide-branch-names", ".*", - "--write", - "--verbose", - ) - - offlineCount, err := offline.CountHeartbeats(offlineQueueFile.Name()) - require.NoError(t, err) - - assert.Equal(t, 27, offlineCount) -} - func TestSendHeartbeats_Err(t *testing.T) { apiURL, router, close := setupTestServer() defer close()