better usage prompt + hash opti on server

This commit is contained in:
2025-08-06 23:09:12 +02:00
parent d479004217
commit 2f777c72ee
10 changed files with 176 additions and 26 deletions

View File

@@ -1,32 +1,39 @@
package add
import (
"cloudsave/pkg/remote"
"cloudsave/pkg/repository"
"context"
"flag"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/google/subcommands"
)
type (
AddCmd struct {
name string
name string
remote string
}
)
func (*AddCmd) Name() string { return "add" }
func (*AddCmd) Synopsis() string { return "Add a folder to the sync list" }
func (*AddCmd) Synopsis() string { return "add a folder to the sync list" }
func (*AddCmd) Usage() string {
return `add:
Add a folder to the sync list
return `Usage: cloudsave add [-name] [-remote] <PATH>
Add a folder to the track list
Options:
`
}
func (p *AddCmd) SetFlags(f *flag.FlagSet) {
f.StringVar(&p.name, "name", "", "Override the name of the game")
f.StringVar(&p.remote, "remote", "", "Defines a remote server to sync with")
}
func (p *AddCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
@@ -50,6 +57,10 @@ func (p *AddCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) s
return subcommands.ExitFailure
}
if len(strings.TrimSpace(p.remote)) > 0 {
remote.Set(m.ID, p.remote)
}
fmt.Println(m.ID)
return subcommands.ExitSuccess

View File

@@ -20,8 +20,9 @@ type (
func (*ListCmd) Name() string { return "apply" }
func (*ListCmd) Synopsis() string { return "apply a backup" }
func (*ListCmd) Usage() string {
return `apply:
Apply a backup
return `Usage: cloudsave apply <GAME_ID> <BACKUP_ID>
Apply a backup
`
}

View File

@@ -22,8 +22,11 @@ type (
func (*ListCmd) Name() string { return "list" }
func (*ListCmd) Synopsis() string { return "list all game registered" }
func (*ListCmd) Usage() string {
return `list:
List all game registered
return `Usage: cloudsave list [-include-backup] [-a]
List all game registered
Options:
`
}

View File

@@ -1,10 +1,10 @@
package pull
import (
"cloudsave/cmd/cli/tools/prompt/credentials"
"cloudsave/pkg/remote/client"
"cloudsave/pkg/repository"
"cloudsave/pkg/tools/archive"
"cloudsave/cmd/cli/tools/prompt/credentials"
"context"
"flag"
"fmt"
@@ -22,8 +22,9 @@ type (
func (*PullCmd) Name() string { return "pull" }
func (*PullCmd) Synopsis() string { return "pull a game save from the remote" }
func (*PullCmd) Usage() string {
return `list:
Pull a game save from the remote
return `Usage: cloudsave pull <GAME_ID>
Pull a game save from the remote
`
}

View File

@@ -20,10 +20,17 @@ type (
)
func (*RemoteCmd) Name() string { return "remote" }
func (*RemoteCmd) Synopsis() string { return "manage remote" }
func (*RemoteCmd) Synopsis() string { return "add or update the remote url" }
func (*RemoteCmd) Usage() string {
return `remote:
manage remove
return `Usage: cloudsave remote <-set|-list>
The -list argument lists all remotes for each registered game.
This command performs a connection test.
The -set argument allow you to set (create or update)
the URL to the remote for a game
Options
`
}

View File

@@ -17,8 +17,10 @@ type (
func (*RemoveCmd) Name() string { return "remove" }
func (*RemoveCmd) Synopsis() string { return "unregister a game" }
func (*RemoveCmd) Usage() string {
return `remove:
Unregister a game
return `Usage: cloudsave remove <GAME_ID>
Unregister a game
Caution: all the backup are deleted
`
}

View File

@@ -20,11 +20,14 @@ type (
}
)
func (*RunCmd) Name() string { return "run" }
func (*RunCmd) Synopsis() string { return "Check and process all the folder" }
func (*RunCmd) Name() string { return "scan" }
func (*RunCmd) Synopsis() string { return "check and process all the folder" }
func (*RunCmd) Usage() string {
return `run:
Check and process all the folder
return `Usage: cloudsave scan
Check if the files have been modified. If so,
the current archive is moved to the backup list
and a new archive is created with a new version number.
`
}

View File

@@ -27,8 +27,9 @@ type (
func (*SyncCmd) Name() string { return "sync" }
func (*SyncCmd) Synopsis() string { return "list all game registered" }
func (*SyncCmd) Usage() string {
return `add:
List all game registered
return `Usage: cloudsave sync
Synchronize the archives with the server defined for each game.
`
}
@@ -47,6 +48,7 @@ func (p *SyncCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{})
r, err := remote.One(g.ID)
if err != nil {
if errors.Is(err, remote.ErrNoRemote) {
fmt.Println(g.Name + ": no remote configured")
continue
}
fmt.Fprintln(os.Stderr, "error: failed to load datastore:", err)
@@ -85,6 +87,7 @@ func (p *SyncCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{})
destroyPg()
slog.Warn("failed to push backup files", "err", err)
}
fmt.Println(g.Name + ": pushed")
continue
}
@@ -136,7 +139,7 @@ func (p *SyncCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{})
continue
}
}
fmt.Println("already up-to-date")
fmt.Println(g.Name + ": already up-to-date")
continue
}
@@ -148,6 +151,7 @@ func (p *SyncCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{})
return subcommands.ExitFailure
}
destroyPg()
fmt.Println(g.Name + ": pushed")
continue
}
@@ -168,6 +172,7 @@ func (p *SyncCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{})
fmt.Fprintln(os.Stderr, "error: failed to synchronize date:", err)
continue
}
fmt.Println(g.Name + ": pulled")
continue
}

View File

@@ -1,9 +1,9 @@
package version
import (
"cloudsave/cmd/cli/tools/prompt/credentials"
"cloudsave/pkg/constants"
"cloudsave/pkg/remote/client"
"cloudsave/cmd/cli/tools/prompt/credentials"
"context"
"flag"
"fmt"
@@ -23,8 +23,11 @@ type (
func (*VersionCmd) Name() string { return "version" }
func (*VersionCmd) Synopsis() string { return "show version and system information" }
func (*VersionCmd) Usage() string {
return `add:
Show version and system information
return `Usage: cloudsave version [-a]
Print the version of the software
Options:
`
}