git-fit 0.16.1 → 0.17.0
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/lib/git-fit.rb +1 -0
- data/lib/git_fit/cli/purge_cli.rb +65 -0
- data/lib/git_fit/cli.rb +3 -0
- data/lib/git_fit/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fb01a16a1c3ffd8bc69b1c7941dcbd5d08e472d4e726ffac27f4147ed268a5de
|
|
4
|
+
data.tar.gz: e32f30371d9e2c9e9879e78e749fb649372c8a0cd644dbdb70042139e60dabd6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 854594f865e691b539e5d487278afab1bd0e26d8b25462b19c458950e59acdae38b8bd9b4d27f48dcb2ac666e55e7666e8b22ee3ad4a6d97f3f19caee72d0387
|
|
7
|
+
data.tar.gz: 0af21c0ba3536d6f48bd7b35099aaff5599afc1a692245b2587ef74e03b2380b082bf177b9efecaaa6ba23492a695a8332abb7377825fda812953be1f47fb697
|
data/lib/git-fit.rb
CHANGED
|
@@ -87,6 +87,7 @@ require_relative 'git_fit/export'
|
|
|
87
87
|
require_relative 'git_fit/db/cli'
|
|
88
88
|
require_relative 'git_fit/install/actions'
|
|
89
89
|
require_relative 'git_fit/cli/install_cli'
|
|
90
|
+
require_relative 'git_fit/cli/purge_cli'
|
|
90
91
|
require_relative 'git_fit/cli/gh_cli'
|
|
91
92
|
require_relative 'git_fit/cli/export'
|
|
92
93
|
require_relative 'git_fit/cli/import_cli'
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GitFit
|
|
4
|
+
class PurgeCLI < Thor
|
|
5
|
+
include Cli::Checkpointable
|
|
6
|
+
|
|
7
|
+
class RecordNotFound < StandardError; end
|
|
8
|
+
class PurgeFailed < StandardError; end
|
|
9
|
+
|
|
10
|
+
def self.exit_on_failure?
|
|
11
|
+
false
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
no_commands do
|
|
15
|
+
def git_fit_config
|
|
16
|
+
@git_fit_config ||= GitFit::Config.new(options[:config])
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
desc 'activity RUN_ID', 'Delete activity by run_id (e.g. keep_9223370467120855807)'
|
|
21
|
+
option :dry_run, type: :boolean, default: false, desc: 'Preview without deleting'
|
|
22
|
+
option :checkpoint, type: :boolean, default: true, desc: 'Run WAL checkpoint after delete'
|
|
23
|
+
|
|
24
|
+
def activity(run_id)
|
|
25
|
+
db = connect_db
|
|
26
|
+
|
|
27
|
+
record = db[:activities].where(run_id: run_id).first
|
|
28
|
+
|
|
29
|
+
unless record
|
|
30
|
+
raise RecordNotFound, "Not found: #{run_id}"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
if options[:dry_run]
|
|
34
|
+
say_status :dry_run, "Would delete activity:", :yellow
|
|
35
|
+
say " run_id: #{record[:run_id]}"
|
|
36
|
+
say " name: #{record[:name]}"
|
|
37
|
+
say " source: #{record[:source]}"
|
|
38
|
+
say " sport_category: #{record[:sport_category]}"
|
|
39
|
+
say " start_date: #{record[:start_date]}"
|
|
40
|
+
say " distance: #{record[:distance]}m" if record[:distance]
|
|
41
|
+
say " moving_time: #{record[:moving_time]}s" if record[:moving_time]
|
|
42
|
+
return
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
db[:dedup_group_members].where(run_id: run_id).delete
|
|
46
|
+
deleted = db[:activities].where(run_id: run_id).delete
|
|
47
|
+
|
|
48
|
+
say_status :deleted, "Removed #{deleted} activity: #{run_id}", :green
|
|
49
|
+
|
|
50
|
+
checkpoint_db(db) if options[:checkpoint]
|
|
51
|
+
rescue RecordNotFound
|
|
52
|
+
raise
|
|
53
|
+
rescue StandardError => e
|
|
54
|
+
raise PurgeFailed, "Purge failed: #{e.message}"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def connect_db
|
|
60
|
+
conn = GitFit::DB::Connection.new(git_fit_config.db_path)
|
|
61
|
+
conn.migrate!
|
|
62
|
+
conn.db
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
data/lib/git_fit/cli.rb
CHANGED
|
@@ -120,6 +120,9 @@ module GitFit
|
|
|
120
120
|
desc 'strava SUBCOMMAND', 'Strava web operations'
|
|
121
121
|
subcommand 'strava', StravaCLI
|
|
122
122
|
|
|
123
|
+
desc 'purge SUBCOMMAND', 'Purge activities from database'
|
|
124
|
+
subcommand 'purge', PurgeCLI
|
|
125
|
+
|
|
123
126
|
desc 'install SUBCOMMAND', 'Install project assets (actions)'
|
|
124
127
|
subcommand 'install', InstallCLI
|
|
125
128
|
|
data/lib/git_fit/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: git-fit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.17.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lax
|
|
@@ -262,6 +262,7 @@ files:
|
|
|
262
262
|
- lib/git_fit/cli/gh_cli.rb
|
|
263
263
|
- lib/git_fit/cli/import_cli.rb
|
|
264
264
|
- lib/git_fit/cli/install_cli.rb
|
|
265
|
+
- lib/git_fit/cli/purge_cli.rb
|
|
265
266
|
- lib/git_fit/cli/strava.rb
|
|
266
267
|
- lib/git_fit/cli/sync.rb
|
|
267
268
|
- lib/git_fit/config.rb
|