From 213981b672e906bb27b2e37f5e3a40acd3e1a330 Mon Sep 17 00:00:00 2001 From: Francisco Moura Date: Thu, 18 Jul 2024 20:44:57 -0300 Subject: [PATCH] fixup! feat(cli): Add add and list applications commands --- cmd/cartesi-rollups-cli/root/app/add/add.go | 6 ++++++ cmd/cartesi-rollups-cli/root/app/app.go | 6 +++--- cmd/cartesi-rollups-cli/root/app/list/list.go | 4 ++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/cartesi-rollups-cli/root/app/add/add.go b/cmd/cartesi-rollups-cli/root/app/add/add.go index e7856e0ee..3deff428b 100644 --- a/cmd/cartesi-rollups-cli/root/app/add/add.go +++ b/cmd/cartesi-rollups-cli/root/app/add/add.go @@ -4,6 +4,7 @@ package add import ( + "fmt" "log/slog" "os" @@ -93,6 +94,10 @@ func init() { func run(cmd *cobra.Command, args []string) { ctx := cmd.Context() + if cmdcommom.Database == nil { + panic("Database was not initialized") + } + var applicationStatus model.ApplicationStatus switch status { case statusRunning: @@ -115,4 +120,5 @@ func run(cmd *cobra.Command, args []string) { err := cmdcommom.Database.InsertApplication(ctx, &application) cobra.CheckErr(err) + fmt.Printf("Application %v successfully added\n", application.ContractAddress) } diff --git a/cmd/cartesi-rollups-cli/root/app/app.go b/cmd/cartesi-rollups-cli/root/app/app.go index a9c89dc11..cf424950c 100644 --- a/cmd/cartesi-rollups-cli/root/app/app.go +++ b/cmd/cartesi-rollups-cli/root/app/app.go @@ -11,9 +11,9 @@ import ( ) var Cmd = &cobra.Command{ - Use: "app", - Short: "Application management related commands", - PreRun: common.Setup, + Use: "app", + Short: "Application management related commands", + PersistentPreRun: common.Setup, } func init() { diff --git a/cmd/cartesi-rollups-cli/root/app/list/list.go b/cmd/cartesi-rollups-cli/root/app/list/list.go index de6fe074e..ca6865e63 100644 --- a/cmd/cartesi-rollups-cli/root/app/list/list.go +++ b/cmd/cartesi-rollups-cli/root/app/list/list.go @@ -23,6 +23,10 @@ cartesi-rollups-cli app list` func run(cmd *cobra.Command, args []string) { ctx := cmd.Context() + if common.Database == nil { + panic("Database was not initialized") + } + applications, err := common.Database.GetAllApplications(ctx) cobra.CheckErr(err) for index, app := range applications {