Skip to content

Commit 9f5309f

Browse files
committed
Improve inventory command, update vendor
1 parent 84edd97 commit 9f5309f

225 files changed

Lines changed: 10698 additions & 4838 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Gopkg.lock

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/cli.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func NewCLIEnv(conf CLIConfig, historyPath string) (*CLIEnv, error) {
8989
fmt.Printf("Enter \"%s\" in the prompt for detailed help information.\n", text.Boldf("help"))
9090
}
9191

92-
srv := cli.NewServer(appEnv.Logger)
92+
srv := cli.NewServer(appEnv.Logger, appEnv.Client)
9393
if f, err := os.Open(historyPath); err == nil {
9494
srv.ReadHistory(f)
9595
f.Close()
@@ -98,7 +98,8 @@ func NewCLIEnv(conf CLIConfig, historyPath string) (*CLIEnv, error) {
9898

9999
srv.SetCommands(
100100
command.NewEVETypesCommand(prompter),
101-
command.NewProductCommand(appEnv.Client, prompter, appEnv.Logger))
101+
command.NewProductCommand(appEnv.Client, prompter, appEnv.Logger),
102+
command.NewInventoryCommand(appEnv.Client, prompter, appEnv.Logger))
102103
srv.SetCtrlCAborts(true)
103104
env := &CLIEnv{
104105
ClientEnv: appEnv,

cli.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,23 @@ type Command interface {
4343
PrintHelp()
4444
}
4545

46+
// authRequirer is implemented by commands that require authentication
47+
// to function. This allows filtering of unworkable commands from being registered.
48+
type authRequirer interface {
49+
Command
50+
RequiresAuth() bool
51+
}
52+
53+
// Authenticator is implemented by a type that is responsible for authentication.
54+
type Authenticator interface {
55+
Authenticated() bool
56+
}
57+
4658
// A Server handles command-line requests and prints responses to standard output.
4759
type Server struct {
4860
*liner.State
4961
logger log.Logger
62+
auth Authenticator
5063

5164
abort chan struct{}
5265

@@ -58,10 +71,11 @@ type Server struct {
5871
}
5972

6073
// NewServer initializes a new CLI server.
61-
func NewServer(logger log.Logger) *Server {
74+
func NewServer(logger log.Logger, a Authenticator) *Server {
6275
return &Server{
6376
State: liner.NewLiner(),
6477
logger: logger,
78+
auth: a,
6579

6680
abort: make(chan struct{}, 1),
6781

@@ -153,6 +167,12 @@ func (srv *Server) PrintHelp() {
153167
154168
Commands:`)
155169
for _, cmd := range srv.commands {
170+
if v, ok := cmd.(authRequirer); ok && v.RequiresAuth() {
171+
if !srv.auth.Authenticated() {
172+
// Not authenticated, skip this command.
173+
continue
174+
}
175+
}
156176
for _, prefix := range cmd.Prefixes() {
157177
fmt.Printf(" %s %s\n", text.Boldf(text.PadTextRight(prefix, 15)), cmd.Description())
158178
break
@@ -183,15 +203,15 @@ func (c quitCommand) Description() string {
183203

184204
func (c quitCommand) PrintHelp() {
185205
fmt.Println()
186-
fmt.Printf(`Command "quit" exits the application.
206+
fmt.Printf(`Command \"%s\" exits the application.
187207
188208
Aliases for quit:
189209
quit
190210
q
191211
exit
192212
\q
193213
194-
%s`, text.WrapText(`Additionally, the program can be exited by sending a SIGINT or SIGKILL signal, for example by pressing CTRL+C.`, text.StandardTerminalWidthInChars))
214+
%s`, text.Boldf("quit"), text.WrapText(`Additionally, the program can be exited by sending a SIGINT or SIGKILL signal, for example by pressing CTRL+C.`, text.StandardTerminalWidthInChars))
195215
fmt.Println()
196216
}
197217

@@ -207,9 +227,19 @@ func (c helpCommand) Prefixes() []string {
207227
func (c helpCommand) Handle(subcmd string, args ...string) {
208228
if len(subcmd) > 0 {
209229
if cmd, ok := c.env.commandLookup[subcmd]; ok {
230+
if aer, ok := cmd.(authRequirer); ok && aer.RequiresAuth() {
231+
if !c.env.auth.Authenticated() {
232+
fmt.Printf("Command \"%s\" requires authentication.\n", text.Boldf(subcmd))
233+
fmt.Printf("Run %s with the %s flag to authenticate. For example:\n", text.Boldf("motki"), text.Boldf("-credentials"))
234+
fmt.Printf(" motki -credentials frank:mypass\n\n")
235+
fmt.Printf("Run %s for additional information.\n", text.Boldf("motki -h"))
236+
return
237+
}
238+
}
210239
cmd.PrintHelp()
211240
return
212241
}
242+
fmt.Println("Unknown command:", subcmd)
213243
}
214244
c.PrintHelp()
215245
}

command/eve_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ about items that exist in the EVE universe.`, text.Boldf("types")), text.Standar
7171
text.Boldf(text.PadTextRight("show [query|typeID]", 25)))
7272
fmt.Println()
7373
fmt.Println()
74-
fmt.Println(text.WrapText(`Note that the registry are identical, and either one accepts an optional integer or string argument. If an integer is given as an argument or in the prompt, the command will attempt to load the Item Type with the given Type ID. If a string is given as an argument or in the prompt, the command will show results matching the input.`, text.StandardTerminalWidthInChars))
74+
fmt.Println(text.WrapText(`Note that the commands are identical, and either one accepts an optional integer or string argument. If an integer is given as an argument or in the prompt, the command will attempt to load the Item Type with the given Type ID. If a string is given as an argument or in the prompt, the command will show results matching the input.`, text.StandardTerminalWidthInChars))
7575
fmt.Println()
7676
}

0 commit comments

Comments
 (0)