Skip to content

Commit 024b39c

Browse files
committed
feat: add automatic update checking
1 parent 09ae09b commit 024b39c

3 files changed

Lines changed: 408 additions & 14 deletions

File tree

cmd/cimis/main.go

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ import (
77
"os"
88
"strconv"
99
"strings"
10+
11+
"github.com/dl-alexandre/cimis-cli/internal/cli"
1012
)
1113

1214
var (
13-
// Version is set during build
14-
Version = "dev"
15-
// GitCommit is set during build
16-
GitCommit = "unknown"
17-
// BuildTime is set during build
18-
BuildTime = "unknown"
15+
// Version is set during build and exported from cli package
16+
Version = cli.Version
17+
// GitCommit is set during build and exported from cli package
18+
GitCommit = cli.GitCommit
19+
// BuildTime is set during build and exported from cli package
20+
BuildTime = cli.BuildTime
1921
)
2022

2123
// parseCacheSize parses cache size strings like "100MB", "1GB" to bytes.
@@ -55,6 +57,9 @@ func parseCacheSize(sizeStr string) int64 {
5557
}
5658

5759
func main() {
60+
// Start automatic update check in background (non-blocking)
61+
cli.AutoUpdateCheck()
62+
5863
if len(os.Args) < 2 {
5964
printUsage()
6065
os.Exit(1)
@@ -69,6 +74,21 @@ func main() {
6974
case "version":
7075
fmt.Printf("cimis %s (%s) built %s\n", Version, GitCommit, BuildTime)
7176

77+
case "check-updates":
78+
force := false
79+
format := "table"
80+
for i := 2; i < len(os.Args); i++ {
81+
if os.Args[i] == "-force" || os.Args[i] == "--force" {
82+
force = true
83+
} else if os.Args[i] == "-json" || os.Args[i] == "--json" {
84+
format = "json"
85+
}
86+
}
87+
if err := cli.CheckForUpdates(force, format); err != nil {
88+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
89+
os.Exit(1)
90+
}
91+
7292
case "init":
7393
cmdInit(*dataDir)
7494

@@ -118,10 +138,12 @@ func printUsage() {
118138
119139
Commands:
120140
version Show version information
141+
check-updates Check for available updates
121142
init Initialize database directories and metadata
122143
fetch Fetch data from CIMIS API (DEPRECATED: use fetch-streaming)
123144
fetch-streaming Fetch with optimized streaming + detailed metrics
124145
ingest Fetch and store using streaming (production default)
146+
ingest-opt Fetch and store using optimized streaming
125147
query Query stored data
126148
stats Show database statistics
127149
verify Verify chunk integrity
@@ -135,6 +157,12 @@ Global Options:
135157
-app-key string CIMIS API app key (or CIMIS_APP_KEY env var)
136158
137159
Examples:
160+
# Check for updates
161+
cimis check-updates
162+
163+
# Force check for updates (bypass cache)
164+
cimis check-updates -force
165+
138166
# Initialize database
139167
cimis init
140168
@@ -150,15 +178,15 @@ Examples:
150178
# Query June 2020 data
151179
cimis query -station 2 -start 2020-06-01 -end 2020-06-30
152180
153-
# Query with caching and performance metrics
154-
cimis query -station 2 -start 2020-06-01 -end 2020-06-30 -cache 100MB -perf
181+
# Query with caching and performance metrics
182+
cimis query -station 2 -start 2020-06-01 -end 2020-06-30 -cache 100MB -perf
155183
156-
# Open CIMIS registration page to get API key
157-
cimis register
184+
# Open CIMIS registration page to get API key
185+
cimis register
158186
159-
# Open CIMIS login page
160-
cimis login
187+
# Open CIMIS login page
188+
cimis login
161189
162-
# Open CIMIS API documentation
163-
cimis api-docs`)
190+
# Open CIMIS API documentation
191+
cimis api-docs`)
164192
}

0 commit comments

Comments
 (0)