From d3da40abd3be7b81ad59b977430b6b8cbbbbc47b Mon Sep 17 00:00:00 2001 From: Alexandre Date: Mon, 3 Feb 2025 09:14:36 +0100 Subject: [PATCH] Some Changes --- go.mod | 1 + go.sum | 2 ++ main.go | 12 +++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 098c76e..f7958c5 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/chzyer/readline v1.5.1 // indirect github.com/creack/pty v1.1.24 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect diff --git a/go.sum b/go.sum index 911bd02..d695d58 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= +github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= diff --git a/main.go b/main.go index cd249c0..51be4e9 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "github.com/chzyer/readline" "github.com/creack/pty" + "github.com/google/shlex" "github.com/spf13/viper" ) @@ -136,7 +137,16 @@ func getPrompt() string { func execInput(input string) error { input = strings.TrimSuffix(input, "\n") - args := strings.Split(input, " ") + + // Diviser la commande en arguments en respectant les guillemets + args, err := shlex.Split(input) + if err != nil { + return fmt.Errorf("Erreur lors de la division des arguments: %v", err) + } + + if len(args) == 0 { + return nil + } // Gérer les commandes intégrées switch args[0] {