first alpha version cli

This commit is contained in:
2025-05-10 21:52:52 +02:00
parent f791b7085c
commit 2380a36271
8 changed files with 275 additions and 12 deletions

View File

@@ -0,0 +1,45 @@
package list
import (
"cloudsave/pkg/game"
"context"
"flag"
"fmt"
"os"
"github.com/google/subcommands"
)
type (
ListCmd struct {
name string
}
)
func (*ListCmd) Name() string { return "list" }
func (*ListCmd) Synopsis() string { return "list all game registered" }
func (*ListCmd) Usage() string {
return `add:
List all game registered
`
}
func (p *ListCmd) SetFlags(f *flag.FlagSet) {
f.StringVar(&p.name, "name", "", "Override the name of the game")
}
func (p *ListCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
datastore, err := game.All()
if err != nil {
fmt.Fprintln(os.Stderr, "error: failed to load datastore:", err)
return subcommands.ExitFailure
}
fmt.Println("ID | NAME | PATH")
fmt.Println("-- | ---- | ----")
for _, metadata := range datastore {
fmt.Println(metadata.ID, "|", metadata.Name, "|", metadata.Path)
}
return subcommands.ExitSuccess
}