Skip to content

Commit 0c4c8c1

Browse files
authored
Phani/cli changes for pagination (#13)
<!-- mesa-description-start --> ## TL;DR Adds `--limit` and `--offset` flags to the `app history` and `deploy history` commands to support pagination. ## Why we made these changes Commands that return a large number of items could be slow, consume too much memory, or hit API rate limits. Fetching results in pages provides a faster and more reliable user experience for users with many resources. ## What changed? - **`cmd/app.go` & `cmd/deploy.go`**: Replaced the `--all` flag with `--limit` (default 100) and `--offset` flags on the `app history` and `deploy history` commands. - **`go.mod` / `go.sum`**: Bumped the `kernel-go-sdk` dependency to `v0.11.1` to support passing the new pagination parameters to the API. - **`README.md`**: Updated documentation to reflect the new `--limit` flag, replacing `--all`. <sup>_Description generated by Mesa. [Update settings](https://app.mesa.dev/onkernel/settings/pull-requests)_</sup> <!-- mesa-description-end -->
1 parent b0c753d commit 0c4c8c1

File tree

6 files changed

+31
-16
lines changed

6 files changed

+31
-16
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Create an API key from the [Kernel dashboard](https://dashboard.onkernel.com).
117117
- `--with-timestamps`, `-t` - Include timestamps in each log line
118118

119119
- `kernel deploy history [app_name]` - Show deployment history
120-
- `--all` - Show deployment history for all applications
120+
- `--limit <n>` - Max deployments to return (default: 100; 0 = all)
121121

122122
### App Management
123123

@@ -133,6 +133,7 @@ Create an API key from the [Kernel dashboard](https://dashboard.onkernel.com).
133133
- `--version <version>` - Filter by version
134134

135135
- `kernel app history <app_name>` - Show deployment history for an app
136+
- `--limit <n>` - Max deployments to return (default: 100; 0 = all)
136137

137138
### Logs
138139

cmd/app.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ func init() {
3939
// Add optional filters for list
4040
appListCmd.Flags().String("name", "", "Filter by application name")
4141
appListCmd.Flags().String("version", "", "Filter by version label")
42+
43+
// Limit rows returned for app history (0 = all)
44+
appHistoryCmd.Flags().Int("limit", 100, "Max deployments to return (default 100)")
4245
}
4346

4447
func runAppList(cmd *cobra.Command, args []string) error {
@@ -109,6 +112,7 @@ func runAppList(cmd *cobra.Command, args []string) error {
109112
func runAppHistory(cmd *cobra.Command, args []string) error {
110113
client := getKernelClient(cmd)
111114
appName := args[0]
115+
lim, _ := cmd.Flags().GetInt("limit")
112116

113117
pterm.Debug.Printf("Fetching deployment history for app '%s'...\n", appName)
114118

@@ -123,7 +127,7 @@ func runAppHistory(cmd *cobra.Command, args []string) error {
123127
return nil
124128
}
125129

126-
if deployments == nil || len(*deployments) == 0 {
130+
if deployments == nil || len(deployments.Items) == 0 {
127131
pterm.Info.Println("No deployments found for this application")
128132
return nil
129133
}
@@ -132,7 +136,8 @@ func runAppHistory(cmd *cobra.Command, args []string) error {
132136
{"Deployment ID", "Created At", "Region", "Status", "Entrypoint", "Reason"},
133137
}
134138

135-
for _, dep := range *deployments {
139+
rows := 0
140+
for _, dep := range deployments.Items {
136141
created := util.FormatLocal(dep.CreatedAt)
137142
status := string(dep.Status)
138143

@@ -144,6 +149,11 @@ func runAppHistory(cmd *cobra.Command, args []string) error {
144149
dep.EntrypointRelPath,
145150
dep.StatusReason,
146151
})
152+
153+
rows++
154+
if lim > 0 && rows >= lim {
155+
break
156+
}
147157
}
148158

149159
printTableNoPad(tableData, true)

cmd/deploy.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func init() {
4848
deployLogsCmd.Flags().BoolP("with-timestamps", "t", false, "Include timestamps in each log line")
4949
deployCmd.AddCommand(deployLogsCmd)
5050

51-
deployHistoryCmd.Flags().Bool("all", false, "Show deployment history for all applications")
51+
deployHistoryCmd.Flags().Int("limit", 100, "Max deployments to return (default 100)")
5252
deployCmd.AddCommand(deployHistoryCmd)
5353
}
5454

@@ -258,12 +258,12 @@ func runDeployLogs(cmd *cobra.Command, args []string) error {
258258
func runDeployHistory(cmd *cobra.Command, args []string) error {
259259
client := getKernelClient(cmd)
260260

261-
all, _ := cmd.Flags().GetBool("all")
261+
lim, _ := cmd.Flags().GetInt("limit")
262262

263263
var appNames []string
264264
if len(args) == 1 {
265265
appNames = []string{args[0]}
266-
} else if all {
266+
} else {
267267
apps, err := client.Apps.List(cmd.Context(), kernel.AppListParams{})
268268
if err != nil {
269269
pterm.Error.Printf("Failed to list applications: %v\n", err)
@@ -273,22 +273,21 @@ func runDeployHistory(cmd *cobra.Command, args []string) error {
273273
appNames = append(appNames, a.AppName)
274274
}
275275
// de-duplicate app names
276-
seen := map[string]struct{}{}
276+
seenApps := map[string]struct{}{}
277277
uniq := make([]string, 0, len(appNames))
278278
for _, n := range appNames {
279-
if _, ok := seen[n]; ok {
279+
if _, ok := seenApps[n]; ok {
280280
continue
281281
}
282-
seen[n] = struct{}{}
282+
seenApps[n] = struct{}{}
283283
uniq = append(uniq, n)
284284
}
285285
appNames = uniq
286-
} else {
287-
pterm.Error.Println("Either provide an app name or use --all")
288-
return nil
289286
}
290287

288+
rows := 0
291289
table := pterm.TableData{{"Deployment ID", "Created At", "Region", "Status", "Entrypoint", "Reason"}}
290+
AppsLoop:
292291
for _, appName := range appNames {
293292
params := kernel.DeploymentListParams{AppName: kernel.Opt(appName)}
294293
pterm.Debug.Printf("Listing deployments for app '%s'...\n", appName)
@@ -297,8 +296,8 @@ func runDeployHistory(cmd *cobra.Command, args []string) error {
297296
pterm.Error.Printf("Failed to list deployments for '%s': %v\n", appName, err)
298297
continue
299298
}
300-
for _, dep := range *deployments {
301-
created := dep.CreatedAt.Format(time.RFC3339)
299+
for _, dep := range deployments.Items {
300+
created := util.FormatLocal(dep.CreatedAt)
302301
status := string(dep.Status)
303302
table = append(table, []string{
304303
dep.ID,
@@ -308,6 +307,10 @@ func runDeployHistory(cmd *cobra.Command, args []string) error {
308307
dep.EntrypointRelPath,
309308
dep.StatusReason,
310309
})
310+
rows++
311+
if lim > 0 && rows >= lim {
312+
break AppsLoop
313+
}
311314
}
312315
}
313316
if len(table) == 1 {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/charmbracelet/fang v0.2.0
99
github.com/golang-jwt/jwt/v5 v5.2.2
1010
github.com/joho/godotenv v1.5.1
11-
github.com/onkernel/kernel-go-sdk v0.11.0
11+
github.com/onkernel/kernel-go-sdk v0.11.1
1212
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
1313
github.com/pterm/pterm v0.12.80
1414
github.com/samber/lo v1.51.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8=
9393
github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig=
9494
github.com/onkernel/kernel-go-sdk v0.11.0 h1:7KUKHiz5t4jdnNCwA8NM1dTtEYdk/AV/RIe8T/HjJwg=
9595
github.com/onkernel/kernel-go-sdk v0.11.0/go.mod h1:q7wsAf+yjpY+w8jbAMciWCtCM0ZUxiw/5o2MSPTZS9E=
96+
github.com/onkernel/kernel-go-sdk v0.11.1 h1:gTxhXtsXrJcrM7KEobEVXa8mPPtRFMlxQwNqkyoCrDI=
97+
github.com/onkernel/kernel-go-sdk v0.11.1/go.mod h1:q7wsAf+yjpY+w8jbAMciWCtCM0ZUxiw/5o2MSPTZS9E=
9698
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
9799
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
98100
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

scripts/go-mod-replace-kernel.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,3 @@ go mod edit -replace=github.com/onkernel/kernel-go-sdk=github.com/stainless-sdks
6767
go mod tidy
6868

6969
echo "go.mod updated to use github.com/stainless-sdks/kernel-go @ $gomod_version"
70-

0 commit comments

Comments
 (0)