Hi, I really like how easily complete allows to add completion to CLI tools using flag but since I use it, I have lost the classic bash completion on filenames for positional arguments.
Take this example:
package main
import (
"flag"
"fmt"
"os"
"github.com/posener/complete/v2"
)
func main() {
printJSON := flag.Bool("json", false, "prints the filename in JSON")
complete.CommandLine()
flag.Parse()
if flag.NArg() < 1 {
fmt.Printf("File argument is missing\n\n")
flag.Usage()
os.Exit(1)
}
if *printJSON {
fmt.Println("{\"filename\": \"" + flag.Arg(0) + "\"}")
} else {
fmt.Println("File: " + flag.Arg(0))
}
}
Without the complete.CommandLine() line, I do not get completion for the -json flag but my positional argument is well completed by bash.
But with this line, I do not get completion anymore.
Is there anything to get the file completion behavior back?
Thank you
Hi, I really like how easily
completeallows to add completion to CLI tools usingflagbut since I use it, I have lost the classic bash completion on filenames for positional arguments.Take this example:
Without the
complete.CommandLine()line, I do not get completion for the-jsonflag but my positional argument is well completed by bash.But with this line, I do not get completion anymore.
Is there anything to get the file completion behavior back?
Thank you