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

Add --color flag #483

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 13 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"

"github.com/alecthomas/kong"
"github.com/fatih/color"
"github.com/zk-org/zk/internal/cli"
"github.com/zk-org/zk/internal/cli/cmd"
"github.com/zk-org/zk/internal/core"
Expand All @@ -31,9 +32,10 @@ var root struct {
Edit cmd.Edit `cmd group:"notes" help:"Edit notes matching the given criteria."`
Tag cmd.Tag `cmd group:"notes" help:"Manage the note tags."`

NotebookDir string `type:path placeholder:PATH help:"Turn off notebook auto-discovery and set manually the notebook where commands are run."`
WorkingDir string `short:W type:path placeholder:PATH help:"Run as if zk was started in <PATH> instead of the current working directory."`
NoInput NoInput `help:"Never prompt or ask for confirmation."`
NotebookDir string `type:path placeholder:PATH help:"Turn off notebook auto-discovery and set manually the notebook where commands are run."`
WorkingDir string `short:W type:path placeholder:PATH help:"Run as if zk was started in <PATH> instead of the current working directory."`
NoInput NoInput `help:"Never prompt or ask for confirmation."`
Color ForceColor `help:"Force colored output"`
// ForceInput is a debugging flag overriding the default value of interaction prompts.
ForceInput string `hidden xor:"input"`
Debug bool `default:"0" hidden help:"Print a debug stacktrace on SIGINT."`
Expand All @@ -52,6 +54,14 @@ func (f NoInput) BeforeApply(container *cli.Container) error {
return nil
}

// When enabled, output colored text even if stdout is not a tty.
type ForceColor bool

func (c ForceColor) BeforeApply() error {
color.NoColor = false
return nil
}

// ShowHelp is the default command run. It's equivalent to `zk --help`.
type ShowHelp struct{}

Expand Down