Skip to content

Commit

Permalink
[+] case insensitive for issue #19
Browse files Browse the repository at this point in the history
  • Loading branch information
WangYihang committed Feb 29, 2020
1 parent 2b297d2 commit 400223b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
# Binary files
platypus
platypus.exe
Platypus
Platypus.exe
27 changes: 20 additions & 7 deletions lib/cli/dispatcher/command_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@ func parseInput(input string) (string, []string) {
if len(args[0]) == 0 {
return "", []string{}
}
if !reflection.Contains(methods, args[0]) {

args[0] = strings.Title(strings.ToLower(args[0]))

var validCommand = false
for _, method := range methods {
if method == args[0] {
validCommand = true
}
}

if validCommand {
return args[0], args[1:]
} else {
log.Error("No such command, use `Help` to get more information")
return "", []string{}
}
return args[0], args[1:]
}

func filterInput(r rune) (rune, bool) {
Expand All @@ -48,11 +59,11 @@ func Run() {

// Construct the IO
l, err := readline.NewEx(&readline.Config{
Prompt: context.Ctx.CommandPrompt,
HistoryFile: "~/.platypus.history",
AutoComplete: completer,
InterruptPrompt: "^C",
EOFPrompt: "exit",
Prompt: context.Ctx.CommandPrompt,
HistoryFile: "~/.platypus.history",
AutoComplete: completer,
InterruptPrompt: "^C",
EOFPrompt: "exit",
HistorySearchFold: true,
FuncFilterInputRune: filterInput,
})
Expand All @@ -62,6 +73,8 @@ func Run() {
}
defer l.Close()

log.Logger.SetOutput(l.Stderr())

// Command loop
for {
line, err := l.Readline()
Expand Down
14 changes: 7 additions & 7 deletions lib/util/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/fatih/color"
)

var logger = log.New(os.Stderr, "", log.Ldate|log.Ltime)
var Logger = log.New(os.Stderr, "", log.Ldate|log.Ltime)

const (
debug = "[DEBUG]"
Expand Down Expand Up @@ -39,7 +39,7 @@ func Data(format string, a ...interface{}) {
for _, mode := range enabled {
if mode == "[DATA]" {
color.Set(color.FgMagenta)
logger.Print(fmt.Sprintf(format, a...))
Logger.Print(fmt.Sprintf(format, a...))
color.Unset()
return
}
Expand All @@ -50,7 +50,7 @@ func Debug(format string, a ...interface{}) {
for _, mode := range enabled {
if mode == "[DEBUG]" {
color.Set(color.FgYellow)
logger.Print(fmt.Sprintf(format, a...))
Logger.Print(fmt.Sprintf(format, a...))
color.Unset()
return
}
Expand All @@ -61,7 +61,7 @@ func Info(format string, a ...interface{}) {
for _, mode := range enabled {
if mode == "[INFO]" {
color.Set(color.FgBlue)
logger.Print(fmt.Sprintf(format, a...))
Logger.Print(fmt.Sprintf(format, a...))
color.Unset()
return
}
Expand All @@ -72,7 +72,7 @@ func Error(format string, a ...interface{}) {
for _, mode := range enabled {
if mode == "[ERROR]" {
color.Set(color.FgRed)
logger.Print(fmt.Sprintf(format, a...))
Logger.Print(fmt.Sprintf(format, a...))
color.Unset()
return
}
Expand All @@ -82,7 +82,7 @@ func Warn(format string, a ...interface{}) {
for _, mode := range enabled {
if mode == "[WARN]" {
color.Set(color.FgMagenta)
logger.Print(fmt.Sprintf(format, a...))
Logger.Print(fmt.Sprintf(format, a...))
color.Unset()
return
}
Expand All @@ -93,7 +93,7 @@ func Success(format string, a ...interface{}) {
for _, mode := range enabled {
if mode == "[SUCCESS]" {
color.Set(color.FgGreen)
logger.Print(fmt.Sprintf(format, a...))
Logger.Print(fmt.Sprintf(format, a...))
color.Unset()
return
}
Expand Down

0 comments on commit 400223b

Please sign in to comment.