able to get product

This commit is contained in:
Gitea
2023-11-30 00:39:51 +03:00
parent 606b94e35b
commit 414dc87091
19 changed files with 2204 additions and 77 deletions

View File

@ -12,24 +12,18 @@ import (
"github.com/teris-io/cli"
)
const (
defaultConfigPath = "config_cli.json"
)
var defaultOutput = os.Stdout
var currentConfig = cliConfig{}
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
log := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelDebug,
ReplaceAttr: func(_ []string, a slog.Attr) slog.Attr {
if a.Key == slog.TimeKey {
a.Value = slog.Int64Value(a.Value.Time().Unix())
}
return a
},
}))
ec, err := app(ctx, log)
ec, err := app(ctx)
if err != nil {
slog.ErrorContext(ctx, "unable to run app", slog.Any("error", err))
}
@ -76,17 +70,20 @@ func setupCLI(ctx context.Context) cli.App {
WithCommand(mainPageState)
apiCategory := setupAPICommand(ctx)
ydbCategory := setupYDBCommand(ctx)
description := fmt.Sprintf("sravni dev cli %s (%s)", kurious.Version(), kurious.Commit())
cliApp := cli.New(description).
WithOption(cli.NewOption("verbose", "Verbose execution").WithChar('v').WithType(cli.TypeBool)).
WithOption(cli.NewOption("json", "JSON outpu format").WithType(cli.TypeBool)).
WithOption(cli.NewOption("config", "Path to config").WithChar('c').WithType(cli.TypeString)).
WithCommand(mainCategory).
WithCommand(apiCategory)
WithCommand(apiCategory).
WithCommand(ydbCategory)
return cliApp
}
func app(ctx context.Context, log *slog.Logger) (exitCode int, err error) {
func app(ctx context.Context) (exitCode int, err error) {
devCLI := setupCLI(ctx)
exitCode = devCLI.Run(os.Args, defaultOutput)