Skip to content

Commit

Permalink
Make --init generate .yml instead of .yaml (go-task#1062)
Browse files Browse the repository at this point in the history
  • Loading branch information
misitebao authored Mar 17, 2023
1 parent 291ee12 commit 15ef1fa
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
15 changes: 9 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- Change the name of the file generated by `task --init` from `Taskfile.yaml`
to `Taskfile.yml`
([#1062](https://github.com/go-task/task/pull/1062) by @misitebao).
- Added new `splitArgs` to the template system
(`{{splitArgs "foo bar 'foo bar baz'"}}`) to ensure string is splitted as
arguments not whitespaces
Expand Down Expand Up @@ -235,7 +238,7 @@
([#597](https://github.com/go-task/task/issues/597), [#598](https://github.com/go-task/task/pull/598)).
- Quote each `{{.CLI_ARGS}}` argument to prevent one with spaces to become many
([#613](https://github.com/go-task/task/pull/613)).
- Fix nil pointer when `cmd:` was left empty
- Fix nil pointer when `cmd:` was left empty
([#612](https://github.com/go-task/task/issues/612), [#614](https://github.com/go-task/task/pull/614)).
- Upgrade [mvdan/sh](https://github.com/mvdan/sh) which contains two
relevant fixes:
Expand Down Expand Up @@ -532,8 +535,8 @@
([#153](https://github.com/go-task/task/issues/153));
- Added ability to globally set environment variables
(
[#138](https://github.com/go-task/task/pull/138),
[#159](https://github.com/go-task/task/pull/159)
[#138](https://github.com/go-task/task/pull/138),
[#159](https://github.com/go-task/task/pull/159)
).

## v2.2.1 - 2018-12-09
Expand Down Expand Up @@ -581,9 +584,9 @@ Version 2.0.0 is here, with a new Taskfile format.

Please, make sure to read the [Taskfile versions](https://github.com/go-task/task/blob/master/TASKFILE_VERSIONS.md) document, since it describes in depth what changed for this version.

* New Taskfile version 2 (https://github.com/go-task/task/issues/77)
* Possibility to have global variables in the `Taskfile.yml` instead of `Taskvars.yml` (https://github.com/go-task/task/issues/66)
* Small improvements and fixes
- New Taskfile version 2 (https://github.com/go-task/task/issues/77)
- Possibility to have global variables in the `Taskfile.yml` instead of `Taskvars.yml` (https://github.com/go-task/task/issues/66)
- Small improvements and fixes

## v1.4.4 - 2017-11-19

Expand Down
2 changes: 1 addition & 1 deletion cmd/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func main() {

pflag.BoolVar(&versionFlag, "version", false, "Show Task version.")
pflag.BoolVarP(&helpFlag, "help", "h", false, "Shows Task usage.")
pflag.BoolVarP(&init, "init", "i", false, "Creates a new Taskfile.yaml in the current folder.")
pflag.BoolVarP(&init, "init", "i", false, "Creates a new Taskfile.yml in the current folder.")
pflag.BoolVarP(&list, "list", "l", false, "Lists tasks with description of current Taskfile.")
pflag.BoolVarP(&listAll, "list-all", "a", false, "Lists tasks with or without a description.")
pflag.BoolVarP(&listJson, "json", "j", false, "Formats task list as JSON.")
Expand Down
2 changes: 1 addition & 1 deletion completion/zsh/_task
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ _arguments \
+ '(operation)' \
{-l,--list}'[list describable tasks]' \
{-a,--list-all}'[list all tasks]' \
{-i,--init}'[create new Taskfile.yaml]' \
{-i,--init}'[create new Taskfile.yml]' \
'(-*)'{-h,--help}'[show help]' \
'(-*)--version[show version and exit]' \
'*: :__task_list'
2 changes: 1 addition & 1 deletion docs/docs/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ variable
| `-f` | `--force` | `bool` | `false` | Forces execution even when the task is up-to-date. |
| `-g` | `--global` | `bool` | `false` | Runs global Taskfile, from `$HOME/Taskfile.{yml,yaml}`. |
| `-h` | `--help` | `bool` | `false` | Shows Task usage. |
| `-i` | `--init` | `bool` | `false` | Creates a new Taskfile.yaml in the current folder. |
| `-i` | `--init` | `bool` | `false` | Creates a new Taskfile.yml in the current folder. |
| `-I` | `--interval` | `string` | `5s` | Sets a different watch interval when using `--watch`, the default being 5 seconds. This string should be a valid [Go Duration](https://pkg.go.dev/time#ParseDuration). |
| `-l` | `--list` | `bool` | `false` | Lists tasks with description of current Taskfile. |
| `-a` | `--list-all` | `bool` | `false` | Lists tasks with or without a description. |
Expand Down
6 changes: 4 additions & 2 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ tasks:
silent: true
`

const defaultTaskfileName = "Taskfile.yml"

// InitTaskfile Taskfile creates a new Taskfile
func InitTaskfile(w io.Writer, dir string) error {
f := filepathext.SmartJoin(dir, "Taskfile.yaml")
f := filepathext.SmartJoin(dir, defaultTaskfileName)

if _, err := os.Stat(f); err == nil {
return ErrTaskfileAlreadyExists
Expand All @@ -33,6 +35,6 @@ func InitTaskfile(w io.Writer, dir string) error {
if err := os.WriteFile(f, []byte(defaultTaskfile), 0o644); err != nil {
return err
}
fmt.Fprintf(w, "Taskfile.yaml created in the current directory\n")
fmt.Fprintf(w, "%s created in the current directory\n", defaultTaskfile)
return nil
}
6 changes: 3 additions & 3 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,19 +704,19 @@ func TestStatusVariables(t *testing.T) {

func TestInit(t *testing.T) {
const dir = "testdata/init"
var file = filepathext.SmartJoin(dir, "Taskfile.yaml")
var file = filepathext.SmartJoin(dir, "Taskfile.yml")

_ = os.Remove(file)
if _, err := os.Stat(file); err == nil {
t.Errorf("Taskfile.yaml should not exist")
t.Errorf("Taskfile.yml should not exist")
}

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

if _, err := os.Stat(file); err != nil {
t.Errorf("Taskfile.yaml should exist")
t.Errorf("Taskfile.yml should exist")
}
_ = os.Remove(file)
}
Expand Down

0 comments on commit 15ef1fa

Please sign in to comment.