Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: modify flags for consistency #59

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions cmd/xc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
var ErrNoMarkdownFile = errors.New("no xc compatible markdown file found")

type config struct {
version, help, short, md bool
filename, heading string
version, help, short, display bool
filename, heading string
}

//go:embed usage.txt
Expand All @@ -49,15 +49,22 @@ func flags() config {
fmt.Print(usage)
}
flag.BoolVar(&cfg.version, "version", false, "show xc version")
flag.BoolVar(&cfg.version, "V", false, "show xc version")

flag.BoolVar(&cfg.help, "help", false, "shows xc usage")
flag.BoolVar(&cfg.help, "h", false, "shows xc usage")

flag.StringVar(&cfg.heading, "heading", "Tasks", "specify xc heading")
flag.StringVar(&cfg.heading, "H", "Tasks", "specify xc heading")

flag.StringVar(&cfg.filename, "file", "", "specify markdown file that contains tasks")
flag.StringVar(&cfg.filename, "f", "", "specify markdown file that contains tasks")

flag.BoolVar(&cfg.short, "short", false, "list task names in a short format")
flag.BoolVar(&cfg.short, "s", false, "list task names in a short format")
flag.BoolVar(&cfg.md, "md", false, "print the markdown for a task rather than running it")

flag.BoolVar(&cfg.display, "d", false, "print the markdown for a task rather than running it")
flag.BoolVar(&cfg.display, "display", false, "print the markdown for a task rather than running it")
flag.Parse()
return cfg
}
Expand Down Expand Up @@ -180,8 +187,8 @@ func runMain() error {
if !ok {
fmt.Printf("task \"%s\" not found\n", tav[0])
}
// xc -md task1
if cfg.md {
// xc -display task1
if cfg.display {
ta.Display(os.Stdout)
return nil
}
Expand Down Expand Up @@ -219,11 +226,17 @@ func completion(tasks models.Tasks) bool {
cmp := complete.New("xc", complete.Command{
GlobalFlags: complete.Flags{
"-version": complete.PredictNothing,
"-V": complete.PredictNothing,
"-h": complete.PredictNothing,
"-short": complete.PredictNothing,
"-help": complete.PredictNothing,
"-f": complete.PredictFiles("*.md"),
"-file": complete.PredictFiles("*.md"),
"-s": complete.PredictNothing,
"-short": complete.PredictNothing,
"-d": complete.PredictNothing,
"-display": complete.PredictNothing,
"-H": complete.PredictNothing,
"-heading": complete.PredictNothing,
},
Sub: nil,
Flags: nil,
Expand Down
7 changes: 4 additions & 3 deletions cmd/xc/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ xc <task> [inputs...]
xc will search in parent directories for convenience.
-f -file <string>
Specify a markdown file that contains tasks (default: "README.md").
-md
-d -display
Print the markdown code of a task rather than running it.
-H -heading <string>
Specify the heading for xc tasks (default: "Tasks").
Expand All @@ -21,10 +21,11 @@ xc
Specify a markdown file that contains tasks (default: "README.md").
-H -heading <string>
Specify the heading for xc tasks (default: "Tasks").
-version
-V -version
Show xc version.
-complete
Install shell completion for xc.
-uncomplete
Uninstall shell completion for xc.
-y Don't prompt user for typing 'yes' when installing completion.
-y
Don't prompt user for typing 'yes' when installing completion.