-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvement of commandline processing #1025
base: master
Are you sure you want to change the base?
Conversation
This is not valid in vanilla and I don't really see the need for this to be valid in dragonfly. Any motivation for this change? |
"This is not valid in vanilla" are you sure? |
Looks like they've changed this. It is actually valid now. Point taken. |
server/cmd/command.go
Outdated
@@ -345,3 +335,41 @@ func exportedFields(command reflect.Value) []reflect.StructField { | |||
} | |||
return fields | |||
} | |||
|
|||
// SplitCommandArgs splits str to args for command execution. | |||
func SplitCommandArgs(str string) []string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function should not be exported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realise that this is used in player.go, but we should probably adapt that in one way or another so that this does not require being exported.
server/cmd/command.go
Outdated
for _, char := range str { | ||
switch char { | ||
case '"': | ||
quote = !quote | ||
case ' ': | ||
if quote { | ||
// writing part of the string. | ||
arg.WriteRune(char) | ||
continue | ||
} | ||
if previousSpace { | ||
// trimming space. | ||
continue | ||
} | ||
// end of the arg. | ||
previousSpace = true | ||
args = append(args, arg.String()) | ||
arg.Reset() | ||
default: | ||
previousSpace = false | ||
arg.WriteRune(char) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a huge fan of re-inventing an entire parser for this. My suggestion would be this:
- Keep using the csv reader, merge the first value in the slice returned with the second value if
first value == "/"
- Remove all empty strings from the slice returned, except if the value is last in the slice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a huge fan of re-inventing an entire parser for this. My suggestion would be this:
* Keep using the csv reader, merge the first value in the slice returned with the second value if `first value == "/"` * Remove all empty strings from the slice returned, except if the value is last in the slice.
yeah maybe writing own parser is not a very good idea
still it's not fully vanilla behavior cause vanilla allows to write commands like so |
with this change you can put as much spaces as you want into the command
something like this:
/tell "Cool guy" hello!
will not result an error any more