53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package point
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
"gitrepo.ru/neonxp/idecnode/pkg/config"
|
|
"gitrepo.ru/neonxp/idecnode/pkg/idec"
|
|
)
|
|
|
|
var PointCommand *cli.Command = &cli.Command{
|
|
Name: "point",
|
|
Description: "Point related commands",
|
|
Flags: []cli.Flag{
|
|
&cli.StringFlag{
|
|
Name: "config",
|
|
DefaultText: "config path",
|
|
Value: "./etc/node.yaml",
|
|
},
|
|
},
|
|
Subcommands: []*cli.Command{
|
|
{
|
|
Name: "add",
|
|
Args: true,
|
|
ArgsUsage: "[username] [email] [password]",
|
|
Action: func(c *cli.Context) error {
|
|
if c.Args().Len() < 3 {
|
|
return errors.New("required 3 arguments")
|
|
}
|
|
configPath := c.String("config")
|
|
cfg, err := config.New(configPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
idecApi, err := idec.New(cfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer idecApi.Close()
|
|
username, email, password := c.Args().Get(0), c.Args().Get(1), c.Args().Get(2)
|
|
authString, err := idecApi.AddPoint(username, email, password)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Println("user registred. auth string", authString)
|
|
|
|
return nil
|
|
},
|
|
},
|
|
},
|
|
}
|