From 54dcc7d00690cda8bf78c983e3fc4307540788ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lie=20DELHAIE?= Date: Sun, 17 Aug 2025 00:42:12 +0200 Subject: [PATCH] show cmd --- cmd/cli/commands/show/show.go | 51 +++++++++++++++++++++++++++++++++++ cmd/cli/main.go | 2 ++ pkg/data/data.go | 4 +-- 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 cmd/cli/commands/show/show.go diff --git a/cmd/cli/commands/show/show.go b/cmd/cli/commands/show/show.go new file mode 100644 index 0000000..4086c92 --- /dev/null +++ b/cmd/cli/commands/show/show.go @@ -0,0 +1,51 @@ +package show + +import ( + "cloudsave/pkg/data" + "context" + "flag" + "fmt" + "os" + + "github.com/google/subcommands" +) + +type ( + ShowCmd struct { + Service *data.Service + } +) + +func (*ShowCmd) Name() string { return "show" } +func (*ShowCmd) Synopsis() string { return "show metadata about game" } +func (*ShowCmd) Usage() string { + return `Usage: cloudsave show + +Show metdata about a game +` +} + +func (p *ShowCmd) SetFlags(f *flag.FlagSet) { +} + +func (p *ShowCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { + if f.NArg() != 1 { + fmt.Fprintln(os.Stderr, "error: missing game ID") + return subcommands.ExitUsageError + } + + gameID := f.Arg(0) + g, err := p.Service.One(gameID) + if err != nil { + fmt.Fprintf(os.Stderr, "error: failed to apply: %s", err) + return subcommands.ExitFailure + } + + fmt.Println(g.Name) + fmt.Println("------") + fmt.Println("Version: ", g.Version) + fmt.Println("Path: ", g.Path) + fmt.Println("MD5: ", g.MD5) + + return subcommands.ExitSuccess +} diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 8ec7531..255e06d 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -8,6 +8,7 @@ import ( "cloudsave/cmd/cli/commands/remote" "cloudsave/cmd/cli/commands/remove" "cloudsave/cmd/cli/commands/run" + "cloudsave/cmd/cli/commands/show" "cloudsave/cmd/cli/commands/sync" "cloudsave/cmd/cli/commands/version" "cloudsave/pkg/data" @@ -48,6 +49,7 @@ func main() { subcommands.Register(&run.RunCmd{Service: s}, "management") subcommands.Register(&list.ListCmd{Service: s}, "management") subcommands.Register(&remove.RemoveCmd{Service: s}, "management") + subcommands.Register(&show.ShowCmd{Service: s}, "management") subcommands.Register(&apply.ListCmd{Service: s}, "restore") diff --git a/pkg/data/data.go b/pkg/data/data.go index 8a6c9b3..ff8063f 100644 --- a/pkg/data/data.go +++ b/pkg/data/data.go @@ -354,7 +354,7 @@ func (l Service) ApplyCurrent(gameID string) error { return err } - return l.apply(path, g.Path) + return l.apply(filepath.Join(path, "data.tar.gz"), g.Path) } func (l Service) ApplyBackup(gameID, backupID string) error { @@ -367,7 +367,7 @@ func (l Service) ApplyBackup(gameID, backupID string) error { return err } - return l.apply(path, g.Path) + return l.apply(filepath.Join(path, "data.tar.gz"), g.Path) } func (l Service) apply(src, dst string) error {