1
0
Fork 0
mirror of https://git.sr.ht/~phw/scotty synced 2025-05-16 04:42:34 +02:00

Use positional arguments for source and target in beam commands

This commit is contained in:
Philipp Wolfer 2023-12-08 17:59:37 +01:00
parent 3ab0ce1cc6
commit 20f1732858
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
4 changed files with 20 additions and 22 deletions

View file

@ -37,11 +37,7 @@ func init() {
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
beamCmd.PersistentFlags().StringP("from", "f", "", "Source service configuration (required)")
beamCmd.MarkPersistentFlagRequired("from")
beamCmd.PersistentFlags().StringP("to", "t", "", "Target service configuration (required)")
beamCmd.MarkPersistentFlagRequired("to")
beamCmd.PersistentFlags().Int64P("timestamp", "s", 0, "Only import data newer then given Unix timestamp")
// beamCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:

View file

@ -26,9 +26,11 @@ import (
)
var beamListensCmd = &cobra.Command{
Use: "listens",
Short: "Transfer listens between two services",
Long: `Transfers listens between two configured services.`,
Use: "listens SOURCE TARGET",
Short: "Transfer listens between two services",
Long: `Transfers listens between two configured services.`,
Args: cobra.ExactArgs(2),
ArgAliases: []string{"source", "target"},
Run: func(cmd *cobra.Command, args []string) {
db, err := storage.New(config.DatabasePath())
cobra.CheckErr(err)
@ -36,7 +38,7 @@ var beamListensCmd = &cobra.Command{
models.ListensExport,
models.ListensImport,
models.ListensResult,
](cmd, &db, "listens")
](cmd, &db, "listens", args[0], args[1])
cobra.CheckErr(err)
exp := backends.ListensExportProcessor{Backend: c.ExpBackend}
imp := backends.ListensImportProcessor{Backend: c.ImpBackend}
@ -56,4 +58,5 @@ func init() {
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// beamListensCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
beamListensCmd.Flags().Int64P("timestamp", "t", 0, "Only import listens newer then given Unix timestamp")
}

View file

@ -26,9 +26,10 @@ import (
)
var beamLovesCmd = &cobra.Command{
Use: "loves",
Use: "loves SOURCE TARGET",
Short: "Transfer loves between two services",
Long: `Transfers loves between two configured services.`,
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
db, err := storage.New(config.DatabasePath())
cobra.CheckErr(err)
@ -36,7 +37,7 @@ var beamLovesCmd = &cobra.Command{
models.LovesExport,
models.LovesImport,
models.LovesResult,
](cmd, &db, "loves")
](cmd, &db, "loves", args[0], args[1])
cobra.CheckErr(err)
exp := backends.LovesExportProcessor{Backend: c.ExpBackend}
imp := backends.LovesImportProcessor{Backend: c.ImpBackend}
@ -57,4 +58,5 @@ func init() {
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// beamLovesCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
beamLovesCmd.Flags().Int64P("timestamp", "t", 0, "Only import loves newer then given Unix timestamp")
}