diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 1991ac2..554932f 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -12,7 +12,7 @@ jobs: name: Test Builds strategy: matrix: - go-version: [1.20.x] + go-version: [1.21.x] os: [ubuntu-latest, windows-latest, macOS-latest] runs-on: ${{ matrix.os }} diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml index e75e50c..c5b9f6c 100644 --- a/.github/workflows/lint-test.yml +++ b/.github/workflows/lint-test.yml @@ -17,7 +17,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.20.x + go-version: 1.21.x - name: Run golangci-lint uses: golangci/golangci-lint-action@v3.3.0 with: diff --git a/go.mod b/go.mod index 76ff44c..e20d1ca 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/projectdiscovery/goflags -go 1.20 +go 1.21 require ( github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08 @@ -11,6 +11,7 @@ require ( ) require ( + github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/miekg/dns v1.1.56 // indirect github.com/projectdiscovery/blackrock v0.0.1 // indirect diff --git a/go.sum b/go.sum index b6dd9e4..db8462b 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08 h1:ox2F0PSMlrAAiAdk github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08/go.mod h1:pCxVEbcm3AMg7ejXyorUXi6HQCzOIBf7zEDVPtw0/U4= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +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/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY= github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= @@ -39,6 +41,7 @@ golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/goflags.go b/goflags.go index 9b40f6d..3432734 100644 --- a/goflags.go +++ b/goflags.go @@ -14,6 +14,7 @@ import ( "time" "github.com/cnf/structhash" + "github.com/google/shlex" fileutil "github.com/projectdiscovery/utils/file" folderutil "github.com/projectdiscovery/utils/folder" permissionutil "github.com/projectdiscovery/utils/permission" @@ -106,10 +107,14 @@ func (flagSet *FlagSet) MergeConfigFile(file string) error { } // Parse parses the flags provided to the library. -func (flagSet *FlagSet) Parse() error { +func (flagSet *FlagSet) Parse(args ...string) error { flagSet.CommandLine.SetOutput(os.Stdout) flagSet.CommandLine.Usage = flagSet.usageFunc - _ = flagSet.CommandLine.Parse(os.Args[1:]) + toParse := os.Args[1:] + if len(args) > 0 { + toParse = args + } + _ = flagSet.CommandLine.Parse(toParse) configFilePath, _ := flagSet.GetConfigFilePath() // migrate data from old config dir to new one @@ -812,3 +817,10 @@ func isZeroValue(f *flag.Flag, value string) bool { func normalizeGroupDescription(description string) string { return strings.ToUpper(description) } + +// GetArgsFromString allows splitting a string into arguments +// following the same rules as the shell. +func GetArgsFromString(str string) []string { + args, _ := shlex.Split(str) + return args +}