summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorDJ O'Leary <dijitol@proton.me>2026-09-07 03:13:01 +0200
committerDJ O'Leary <dijitol@proton.me>2026-09-07 03:13:01 +0200
commit2f61b07aea82fa0f5b98686bdfeba2e297c7b21b (patch)
treeb55f588e935b11decd782e7bd0a6c98f060e1654 /main.go
parent5d3efcc64fc9664e061b44659f85aeec03a56685 (diff)
refactor(cardmarket): move handlers to own directoryHEADmain
Diffstat (limited to 'main.go')
-rw-r--r--main.go49
1 files changed, 42 insertions, 7 deletions
diff --git a/main.go b/main.go
index 68e4adf..4fb8231 100644
--- a/main.go
+++ b/main.go
@@ -3,6 +3,7 @@ package main
import (
"context"
"encoding/json"
+ "errors"
"flag"
"fmt"
"io"
@@ -10,6 +11,7 @@ import (
"os"
"codeberg.org/dijitol/trading_post/src/cardmarket"
+ "codeberg.org/dijitol/trading_post/src/cardmarket/handlers"
"codeberg.org/dijitol/trading_post/src/cli"
"codeberg.org/dijitol/trading_post/src/config"
"codeberg.org/dijitol/trading_post/src/oauth"
@@ -52,7 +54,7 @@ func Run(
"account",
"[account] outputs information about the owner of the credentials",
func(_ *flag.FlagSet) error {
- account, err := client.GetAccountInformation(ctx)
+ account, err := handlers.GetAccountInformation(ctx, client)
if err != nil {
return err
}
@@ -62,7 +64,34 @@ func Run(
return err
}
- fmt.Fprintln(stdout, string(out))
+ _, _ = fmt.Fprintln(stdout, string(out))
+
+ return nil
+ },
+ )
+ sg.AddSubcommand(
+ "vacation",
+ "[vacation] sets the vacation state",
+ func(fs *flag.FlagSet) error {
+ onVacation := fs.Bool("onVacation", false, "flag if the user is on vacation or not")
+ cancelOrders := fs.Bool("cancelOrders", false, "flag to cancel open orders, resp. request cancellation for open orders")
+ relistItems := fs.Bool("relistItems", false, "flag to relist items for cancelled orders; only applies if (cancelOrders) is also provided and set to true for all orders, that are effectively cancelled")
+
+ if err := fs.Parse(args[2:]); err != nil {
+ return err
+ }
+
+ if err := handlers.SetVacationState(
+ ctx,
+ client,
+ *onVacation,
+ cancelOrders,
+ relistItems,
+ ); err != nil {
+ return err
+ }
+
+ _, _ = fmt.Fprintln(stdout, "")
return nil
},
@@ -71,7 +100,7 @@ func Run(
"games",
"[games] outputs all the games",
func(_ *flag.FlagSet) error {
- games, err := client.GetGames(ctx)
+ games, err := handlers.GetGames(ctx, client)
if err != nil {
return err
}
@@ -81,18 +110,24 @@ func Run(
return err
}
- fmt.Fprintln(stdout, string(out))
+ _, _ = fmt.Fprintln(stdout, string(out))
return nil
},
)
if len(args) < 2 { // 1st if program name, 2nd is subcommand
- return fmt.Errorf("error: missing subcommand - usage: `trading_post [command]`\n%s", sg.Usage())
+ return fmt.Errorf("error: missing subcommand\n\nusage: `trading_post [subcommand]`\n%s", sg.Usage())
+ }
+
+ subcmd := args[1]
+
+ if subcmd == "--help" || subcmd == "-h" {
+ return fmt.Errorf("usage: `trading_post [subcommand]`\n%s", sg.Usage())
}
- if err := sg.ExecSubcommand(args[1]); err != nil {
- return err
+ if err := sg.ExecSubcommand(subcmd); err != nil {
+ return errors.Join(err, fmt.Errorf("\nusage: `trading_post [subcommand]`\n%s", sg.Usage()))
}
return nil