mirror of
https://github.com/Luzifer/rconfig.git
synced 2024-11-09 16:30:04 +00:00
Added Args()
function to retrieve positional arguments
This commit is contained in:
parent
d194dded1e
commit
d8a62bd35f
2 changed files with 31 additions and 0 deletions
|
@ -44,6 +44,11 @@ func Parse(config interface{}) error {
|
|||
return parse(config, nil)
|
||||
}
|
||||
|
||||
// Args returns the non-flag command-line arguments.
|
||||
func Args() []string {
|
||||
return fs.Args()
|
||||
}
|
||||
|
||||
// Usage prints a basic usage with the corresponding defaults for the flags to
|
||||
// os.Stdout. The defaults are derived from the `default` struct-tag and the ENV.
|
||||
func Usage() {
|
||||
|
|
|
@ -80,4 +80,30 @@ var _ = Describe("Testing general parsing", func() {
|
|||
})
|
||||
})
|
||||
|
||||
Context("with additional arguments", func() {
|
||||
BeforeEach(func() {
|
||||
cfg = t{}
|
||||
args = []string{
|
||||
"--shell=test23",
|
||||
"-t", "bla",
|
||||
"positional1", "positional2",
|
||||
}
|
||||
})
|
||||
|
||||
JustBeforeEach(func() {
|
||||
err = parse(&cfg, args)
|
||||
})
|
||||
|
||||
It("should not have errored", func() { Expect(err).NotTo(HaveOccurred()) })
|
||||
It("should have parsed the expected values", func() {
|
||||
Expect(cfg.Test).To(Equal("test23"))
|
||||
Expect(cfg.Test2).To(Equal("bla"))
|
||||
Expect(cfg.SadFlag).To(Equal(""))
|
||||
Expect(cfg.DefaultFlag).To(Equal("goo"))
|
||||
})
|
||||
It("should have detected the positional arguments", func() {
|
||||
Expect(Args()).To(Equal([]string{"positional1", "positional2"}))
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue