Skip to content

Commit

Permalink
Merge pull request #185 from projectdiscovery/allow-custom-args
Browse files Browse the repository at this point in the history
allow custom args
  • Loading branch information
Mzack9999 authored May 24, 2024
2 parents 574c0cb + 5b4cb25 commit f950823
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
with:
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module github.com/projectdiscovery/goflags

go 1.20
go 1.21

require (
github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.9.0
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db
Expand All @@ -29,7 +30,7 @@ require (
github.com/gorilla/css v1.0.0 // indirect
github.com/microcosm-cc/bluemonday v1.0.25 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/projectdiscovery/utils v0.0.94
github.com/projectdiscovery/utils v0.1.0
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect
golang.org/x/net v0.23.0 // indirect
)
7 changes: 5 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -20,8 +22,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/projectdiscovery/blackrock v0.0.1 h1:lHQqhaaEFjgf5WkuItbpeCZv2DUIE45k0VbGJyft6LQ=
github.com/projectdiscovery/blackrock v0.0.1/go.mod h1:ANUtjDfaVrqB453bzToU+YB4cUbvBRpLvEwoWIwlTss=
github.com/projectdiscovery/utils v0.0.94 h1:2zzFEjMkq/Ei/o3NIA2SWTkhfGHMkBy0T3aIzq0vizo=
github.com/projectdiscovery/utils v0.0.94/go.mod h1:wxPi+kCsLm5JCLMkZJyGwS+4Mn4PaPHHf0ayE8JphOw=
github.com/projectdiscovery/utils v0.1.0 h1:r7Z/s2CBktJ0bnSN410lzOhD8S/0IxmzmFxkQudYKps=
github.com/projectdiscovery/utils v0.1.0/go.mod h1:RaBdJLTKF5FKZ/RtMeccqFBtpsSjaggVw6/oPTpDD40=
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d h1:hrujxIzL1woJ7AwssoOcM/tq5JjjG2yYOc8odClEiXA=
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
Expand All @@ -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=
Expand Down
16 changes: 14 additions & 2 deletions goflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit f950823

Please sign in to comment.