docs and private funcs
This commit is contained in:
parent
7e3529aaee
commit
869ca3c290
3 changed files with 11 additions and 9 deletions
|
|
@ -19,7 +19,9 @@ type Val interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// with generic Val field, instantiate like Flag[string]
|
// with generic Val field, instantiate like Flag[string]
|
||||||
// TODO: probably struct inheritance would be cleaner, but Flag[bool] is cooler than FlagBool.
|
// NOTE: struct inheritance would be easier, but Flag[bool] is much cooler than FlagBool.
|
||||||
|
// and actually more readable for the initOpts function, which serves as documentation.
|
||||||
|
// so the complexity seems to be all paid up front here in this pkg.
|
||||||
type Flag[T Val] struct {
|
type Flag[T Val] struct {
|
||||||
Long string
|
Long string
|
||||||
Short string
|
Short string
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ type options struct {
|
||||||
Help flags.Flag[bool]
|
Help flags.Flag[bool]
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitOpts() options {
|
func initOpts() options {
|
||||||
return options{
|
return options{
|
||||||
flags.Arg{"", "midfix file descriptor"},
|
flags.Arg{"", "midfix file descriptor"},
|
||||||
flags.Arg{"", "tags to add to new file"},
|
flags.Arg{"", "tags to add to new file"},
|
||||||
|
|
@ -21,8 +21,8 @@ func InitOpts() options {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseArgs(args []string) options {
|
func parseArgs(args []string) options {
|
||||||
opts := InitOpts()
|
opts := initOpts()
|
||||||
for i, arg := range args {
|
for i, arg := range args {
|
||||||
switch {
|
switch {
|
||||||
case i == 0 && !flags.HasDashPrefix(arg):
|
case i == 0 && !flags.HasDashPrefix(arg):
|
||||||
|
|
@ -41,6 +41,6 @@ func ParseArgs(args []string) options {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Next(args []string) {
|
func Next(args []string) {
|
||||||
opts := ParseArgs(args)
|
opts := parseArgs(args)
|
||||||
fmt.Println(opts)
|
fmt.Println(opts)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ type options struct {
|
||||||
Help flags.Flag[bool]
|
Help flags.Flag[bool]
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitOpts() options {
|
func initOpts() options {
|
||||||
return options{
|
return options{
|
||||||
flags.Arg{"", "tag query"},
|
flags.Arg{"", "tag query"},
|
||||||
flags.Flag[string]{"--date", "-d", "", "date range"},
|
flags.Flag[string]{"--date", "-d", "", "date range"},
|
||||||
|
|
@ -22,8 +22,8 @@ func InitOpts() options {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseArgs(args []string) options {
|
func parseArgs(args []string) options {
|
||||||
opts := InitOpts()
|
opts := initOpts()
|
||||||
for i, arg := range args {
|
for i, arg := range args {
|
||||||
switch {
|
switch {
|
||||||
case i == 0 && !flags.HasDashPrefix(arg):
|
case i == 0 && !flags.HasDashPrefix(arg):
|
||||||
|
|
@ -45,6 +45,6 @@ func ParseArgs(args []string) options {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Tag(args []string) {
|
func Tag(args []string) {
|
||||||
opts := ParseArgs(args)
|
opts := parseArgs(args)
|
||||||
fmt.Println(opts)
|
fmt.Println(opts)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue