diff --git a/README.md b/README.md index 1387731..46b6d5d 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ Create an API key from the [Kernel dashboard](https://dashboard.onkernel.com). - `--with-timestamps`, `-t` - Include timestamps in each log line - `kernel deploy history [app_name]` - Show deployment history - - `--all` - Show deployment history for all applications + - `--limit ` - Max deployments to return (default: 100; 0 = all) ### App Management @@ -133,6 +133,7 @@ Create an API key from the [Kernel dashboard](https://dashboard.onkernel.com). - `--version ` - Filter by version - `kernel app history ` - Show deployment history for an app + - `--limit ` - Max deployments to return (default: 100; 0 = all) ### Logs diff --git a/cmd/app.go b/cmd/app.go index 1c06fdf..7c4dba8 100644 --- a/cmd/app.go +++ b/cmd/app.go @@ -39,6 +39,9 @@ func init() { // Add optional filters for list appListCmd.Flags().String("name", "", "Filter by application name") appListCmd.Flags().String("version", "", "Filter by version label") + + // Limit rows returned for app history (0 = all) + appHistoryCmd.Flags().Int("limit", 100, "Max deployments to return (default 100)") } func runAppList(cmd *cobra.Command, args []string) error { @@ -109,6 +112,7 @@ func runAppList(cmd *cobra.Command, args []string) error { func runAppHistory(cmd *cobra.Command, args []string) error { client := getKernelClient(cmd) appName := args[0] + lim, _ := cmd.Flags().GetInt("limit") pterm.Debug.Printf("Fetching deployment history for app '%s'...\n", appName) @@ -123,7 +127,7 @@ func runAppHistory(cmd *cobra.Command, args []string) error { return nil } - if deployments == nil || len(*deployments) == 0 { + if deployments == nil || len(deployments.Items) == 0 { pterm.Info.Println("No deployments found for this application") return nil } @@ -132,7 +136,8 @@ func runAppHistory(cmd *cobra.Command, args []string) error { {"Deployment ID", "Created At", "Region", "Status", "Entrypoint", "Reason"}, } - for _, dep := range *deployments { + rows := 0 + for _, dep := range deployments.Items { created := util.FormatLocal(dep.CreatedAt) status := string(dep.Status) @@ -144,6 +149,11 @@ func runAppHistory(cmd *cobra.Command, args []string) error { dep.EntrypointRelPath, dep.StatusReason, }) + + rows++ + if lim > 0 && rows >= lim { + break + } } printTableNoPad(tableData, true) diff --git a/cmd/deploy.go b/cmd/deploy.go index 3b26e3a..fae6b68 100644 --- a/cmd/deploy.go +++ b/cmd/deploy.go @@ -48,7 +48,7 @@ func init() { deployLogsCmd.Flags().BoolP("with-timestamps", "t", false, "Include timestamps in each log line") deployCmd.AddCommand(deployLogsCmd) - deployHistoryCmd.Flags().Bool("all", false, "Show deployment history for all applications") + deployHistoryCmd.Flags().Int("limit", 100, "Max deployments to return (default 100)") deployCmd.AddCommand(deployHistoryCmd) } @@ -258,12 +258,12 @@ func runDeployLogs(cmd *cobra.Command, args []string) error { func runDeployHistory(cmd *cobra.Command, args []string) error { client := getKernelClient(cmd) - all, _ := cmd.Flags().GetBool("all") + lim, _ := cmd.Flags().GetInt("limit") var appNames []string if len(args) == 1 { appNames = []string{args[0]} - } else if all { + } else { apps, err := client.Apps.List(cmd.Context(), kernel.AppListParams{}) if err != nil { pterm.Error.Printf("Failed to list applications: %v\n", err) @@ -273,22 +273,21 @@ func runDeployHistory(cmd *cobra.Command, args []string) error { appNames = append(appNames, a.AppName) } // de-duplicate app names - seen := map[string]struct{}{} + seenApps := map[string]struct{}{} uniq := make([]string, 0, len(appNames)) for _, n := range appNames { - if _, ok := seen[n]; ok { + if _, ok := seenApps[n]; ok { continue } - seen[n] = struct{}{} + seenApps[n] = struct{}{} uniq = append(uniq, n) } appNames = uniq - } else { - pterm.Error.Println("Either provide an app name or use --all") - return nil } + rows := 0 table := pterm.TableData{{"Deployment ID", "Created At", "Region", "Status", "Entrypoint", "Reason"}} +AppsLoop: for _, appName := range appNames { params := kernel.DeploymentListParams{AppName: kernel.Opt(appName)} pterm.Debug.Printf("Listing deployments for app '%s'...\n", appName) @@ -297,8 +296,8 @@ func runDeployHistory(cmd *cobra.Command, args []string) error { pterm.Error.Printf("Failed to list deployments for '%s': %v\n", appName, err) continue } - for _, dep := range *deployments { - created := dep.CreatedAt.Format(time.RFC3339) + for _, dep := range deployments.Items { + created := util.FormatLocal(dep.CreatedAt) status := string(dep.Status) table = append(table, []string{ dep.ID, @@ -308,6 +307,10 @@ func runDeployHistory(cmd *cobra.Command, args []string) error { dep.EntrypointRelPath, dep.StatusReason, }) + rows++ + if lim > 0 && rows >= lim { + break AppsLoop + } } } if len(table) == 1 { diff --git a/go.mod b/go.mod index 50207da..3032472 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/charmbracelet/fang v0.2.0 github.com/golang-jwt/jwt/v5 v5.2.2 github.com/joho/godotenv v1.5.1 - github.com/onkernel/kernel-go-sdk v0.11.0 + github.com/onkernel/kernel-go-sdk v0.11.1 github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c github.com/pterm/pterm v0.12.80 github.com/samber/lo v1.51.0 diff --git a/go.sum b/go.sum index 0e9577d..f9360bc 100644 --- a/go.sum +++ b/go.sum @@ -93,6 +93,8 @@ github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8= github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig= github.com/onkernel/kernel-go-sdk v0.11.0 h1:7KUKHiz5t4jdnNCwA8NM1dTtEYdk/AV/RIe8T/HjJwg= github.com/onkernel/kernel-go-sdk v0.11.0/go.mod h1:q7wsAf+yjpY+w8jbAMciWCtCM0ZUxiw/5o2MSPTZS9E= +github.com/onkernel/kernel-go-sdk v0.11.1 h1:gTxhXtsXrJcrM7KEobEVXa8mPPtRFMlxQwNqkyoCrDI= +github.com/onkernel/kernel-go-sdk v0.11.1/go.mod h1:q7wsAf+yjpY+w8jbAMciWCtCM0ZUxiw/5o2MSPTZS9E= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/scripts/go-mod-replace-kernel.sh b/scripts/go-mod-replace-kernel.sh index 7a0adfe..c671cdd 100755 --- a/scripts/go-mod-replace-kernel.sh +++ b/scripts/go-mod-replace-kernel.sh @@ -67,4 +67,3 @@ go mod edit -replace=github.com/onkernel/kernel-go-sdk=github.com/stainless-sdks go mod tidy echo "go.mod updated to use github.com/stainless-sdks/kernel-go @ $gomod_version" -