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

Make Taskfile initialization less verbose by default #2011

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion cmd/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ func run() error {
if err != nil {
return err
}
if err := task.InitTaskfile(os.Stdout, wd); err != nil {

verbosity := uint8(1) // Print filename only
if flags.Silent {
verbosity = 0 // Print nothing
} else if flags.Verbose {
verbosity = 2 // Print file contents + filename
}

if err := task.InitTaskfile(os.Stdout, wd, verbosity); err != nil {
return err
}
return nil
Expand Down
20 changes: 17 additions & 3 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ tasks:

const defaultTaskfileName = "Taskfile.yml"

// InitTaskfile Taskfile creates a new Taskfile
func InitTaskfile(w io.Writer, dir string) error {
// InitTaskfile creates a new Taskfile
//
// verbosity specifies how much to print to the terminal:
//
// 0 = Don't print anything
//
// 1 = Print filename only
//
// 2 = Print file contents + filename
func InitTaskfile(w io.Writer, dir string, verbosity uint8) error {
f := filepathext.SmartJoin(dir, defaultTaskfileName)

if _, err := os.Stat(f); err == nil {
Expand All @@ -36,6 +44,12 @@ func InitTaskfile(w io.Writer, dir string) error {
if err := os.WriteFile(f, []byte(defaultTaskfile), 0o644); err != nil {
return err
}
fmt.Fprintf(w, "%s created in the current directory\n", defaultTaskfile)

if verbosity > 0 {
if verbosity > 1 {
fmt.Fprintf(w, "%s\n", defaultTaskfile)
}
fmt.Fprintf(w, "%s created in the current directory\n", defaultTaskfileName)
}
return nil
}
2 changes: 1 addition & 1 deletion task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ func TestInit(t *testing.T) {
t.Errorf("Taskfile.yml should not exist")
}

if err := task.InitTaskfile(io.Discard, dir); err != nil {
if err := task.InitTaskfile(io.Discard, dir, 0); err != nil {
t.Error(err)
}

Expand Down
Loading