diff --git a/icommand/console.go b/icommand/console.go index 0e06777..2a966a0 100644 --- a/icommand/console.go +++ b/icommand/console.go @@ -72,6 +72,9 @@ var CmdConsole = cli.Command{ shell.AddCmd(policy(shell, ctx)) shell.AddCmd(role(shell, ctx)) shell.AddCmd(schedule(shell, ctx)) + shell.AddCmd(users(shell, ctx)) + shell.AddCmd(logger(shell, ctx)) + shell.AddCmd(logout(shell, ctx)) // run shell shell.Run() diff --git a/icommand/login.go b/icommand/login.go index 53099a2..1e56259 100644 --- a/icommand/login.go +++ b/icommand/login.go @@ -1,6 +1,11 @@ package icommand -import "github.com/abiosoft/ishell" +import ( + "github.com/abiosoft/ishell" + "github.com/ernestio/ernest-cli/command" + h "github.com/ernestio/ernest-cli/helper" + "github.com/urfave/cli" +) func loginICmd(shell *ishell.Shell) func(c *ishell.Context) { return func(c *ishell.Context) { @@ -18,3 +23,15 @@ func loginICmd(shell *ishell.Shell) func(c *ishell.Context) { updatePrompt(shell) } } + +func logout(shell *ishell.Shell, ctx *cli.Context) *ishell.Cmd { + return &ishell.Cmd{ + Name: "logout", + Help: h.T("logout.description"), + Func: func(c *ishell.Context) { + var args []string + var flags map[string]string + command.Logout.Run(getContext(ctx, args, flags)) + }, + } +} diff --git a/icommand/preferences.go b/icommand/preferences.go new file mode 100644 index 0000000..edad14d --- /dev/null +++ b/icommand/preferences.go @@ -0,0 +1,58 @@ +package icommand + +import ( + "github.com/abiosoft/ishell" + "github.com/ernestio/ernest-cli/command" + h "github.com/ernestio/ernest-cli/helper" + "github.com/urfave/cli" +) + +func logger(shell *ishell.Shell, ctx *cli.Context) *ishell.Cmd { + cmd := &ishell.Cmd{ + Name: "logger", + Help: "Logger management", + } + + cmd.AddCmd(&ishell.Cmd{ + Name: "list", + Help: h.T("logger.list.description"), + Func: func(c *ishell.Context) { + var args []string + var flags map[string]string + command.ListLoggers.Run(getContext(ctx, args, flags)) + }, + }) + + cmd.AddCmd(&ishell.Cmd{ + Name: "add", + Help: h.T("logger.set.description"), + Func: func(c *ishell.Context) { + args := mapArgs(c, map[string]input{ + "name": input{out: "Logger name : "}, + }) + flags := mapFlags(c, map[string]input{ + "logfile": input{out: "Log File : "}, + "hostname": input{out: "Hostname : "}, + "port": input{out: "Port : "}, + "timeout": input{out: "Timeout : "}, + "token": input{out: "Token : "}, + "env": input{out: "Environment : "}, + }) + command.SetLogger.Run(getContext(ctx, args, flags)) + }, + }) + + cmd.AddCmd(&ishell.Cmd{ + Name: "delete", + Help: h.T("logger.del.description"), + Func: func(c *ishell.Context) { + var flags map[string]string + args := mapArgs(c, map[string]input{ + "name": input{out: "Notification name : "}, + }) + command.DelLogger.Run(getContext(ctx, args, flags)) + }, + }) + + return cmd +} diff --git a/icommand/user.go b/icommand/user.go new file mode 100644 index 0000000..1149a6d --- /dev/null +++ b/icommand/user.go @@ -0,0 +1,140 @@ +package icommand + +import ( + "github.com/abiosoft/ishell" + "github.com/ernestio/ernest-cli/command" + h "github.com/ernestio/ernest-cli/helper" + "github.com/urfave/cli" +) + +func users(shell *ishell.Shell, ctx *cli.Context) *ishell.Cmd { + cmd := &ishell.Cmd{ + Name: "user", + Help: "Users management", + } + + cmd.AddCmd(&ishell.Cmd{ + Name: "list", + Help: h.T("user.list.description"), + Func: func(c *ishell.Context) { + var args []string + var flags map[string]string + command.ListUsers.Run(getContext(ctx, args, flags)) + }, + }) + + cmd.AddCmd(&ishell.Cmd{ + Name: "create", + Help: h.T("user.create.description"), + Func: func(c *ishell.Context) { + var args []string + flags := mapFlags(c, map[string]input{ + "email": input{out: "Email : "}, + }) + args = mapArgs(c, map[string]input{ + "username": input{out: "Username : "}, + "pasword": input{out: "Password : "}, + }) + command.CreateUser.Run(getContext(ctx, args, flags)) + }, + }) + + cmd.AddCmd(&ishell.Cmd{ + Name: "password", + Help: h.T("user.password.description"), + Func: func(c *ishell.Context) { + var args []string + flags := mapFlags(c, map[string]input{ + "user": input{out: "Username : "}, + "password": input{out: "Password : "}, + }) + command.DeletePolicy.Run(getContext(ctx, args, flags)) + + command.PasswordUser.Run(getContext(ctx, args, flags)) + }, + }) + + cmd.AddCmd(&ishell.Cmd{ + Name: "disable", + Help: h.T("user.disable.description"), + Func: func(c *ishell.Context) { + var flags map[string]string + args := mapArgs(c, map[string]input{ + "user": input{out: "Username : "}, + }) + command.UpdateNotification.Run(getContext(ctx, args, flags)) + }, + }) + + cmd.AddCmd(&ishell.Cmd{ + Name: "info", + Help: h.T("user.info.description"), + Func: func(c *ishell.Context) { + var args []string + var flags map[string]string + command.InfoUser.Run(getContext(ctx, args, flags)) + }, + }) + + cmd.AddCmd(&ishell.Cmd{ + Name: "add-admin", + Help: h.T("user.admin.add.description"), + Func: func(c *ishell.Context) { + var flags map[string]string + args := mapArgs(c, map[string]input{ + "user": input{out: "Username : "}, + }) + command.AddAdminUser.Run(getContext(ctx, args, flags)) + }, + }) + + cmd.AddCmd(&ishell.Cmd{ + Name: "rm-admin", + Help: h.T("user.admin.rm.description"), + Func: func(c *ishell.Context) { + var flags map[string]string + args := mapArgs(c, map[string]input{ + "user": input{out: "Username : "}, + }) + command.RmAdminUser.Run(getContext(ctx, args, flags)) + }, + }) + + cmd.AddCmd(&ishell.Cmd{ + Name: "enable-mfa", + Help: h.T("user.enable-mfa.description"), + Func: func(c *ishell.Context) { + var args []string + flags := mapFlags(c, map[string]input{ + "user-name": input{out: "Username : "}, + }) + command.EnableMFA.Run(getContext(ctx, args, flags)) + }, + }) + + cmd.AddCmd(&ishell.Cmd{ + Name: "disable-mfa", + Help: h.T("user.disable-mfa.description"), + Func: func(c *ishell.Context) { + var args []string + flags := mapFlags(c, map[string]input{ + "user-name": input{out: "Username : "}, + }) + command.DisableMFA.Run(getContext(ctx, args, flags)) + }, + }) + + cmd.AddCmd(&ishell.Cmd{ + Name: "reset-mfa", + Help: h.T("user.reset-mfa.description"), + Func: func(c *ishell.Context) { + var args []string + flags := mapFlags(c, map[string]input{ + "user-name": input{out: "Username : "}, + }) + command.ResetMFA.Run(getContext(ctx, args, flags)) + }, + }) + + return cmd +}