-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nushell: use lexer to patch arguments
- Loading branch information
Showing
3 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package nushell | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/rsteube/carapace/internal/lexer" | ||
) | ||
|
||
// Patch uses the lexer to parse and patch given arguments. | ||
// see https://www.nushell.sh/book/working_with_strings.html | ||
func Patch(args []string) []string { | ||
for index, arg := range args { | ||
if len(arg) == 0 { | ||
continue | ||
} | ||
|
||
switch arg[0] { | ||
case '"', "'"[0]: | ||
if tokenset, err := lexer.Split(arg, false); err == nil { | ||
args[index] = tokenset.Tokens[0] | ||
} | ||
case '`': | ||
args[index] = strings.Trim(arg, "`") | ||
} | ||
} | ||
return args | ||
} |