Skip to content

Commit

Permalink
Merge pull request #54 from tooploox/bdymowski/oya-init-projectName
Browse files Browse the repository at this point in the history
Add project name as oya init argument
  • Loading branch information
bart84ek authored May 17, 2019
2 parents 611bcb6 + 0ff591e commit c6c3093
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $ curl https://oya.sh/get | bash
Initialize project.

``` bash
$ oya init
$ oya init OyaExample
```

Define a task you can run:
Expand Down Expand Up @@ -65,16 +65,13 @@ $ oya --version
You can create Oyafile by hand or with init command.

``` bash
$ oya init
$ oya init OyaExample
$ cat Oyafile
```
``` yaml
Project: project
Project: OyaExample
```
Don’t forget to change project name.
# Tasks
Oya task is a bash script defined as a Oyafile key.
Expand Down
6 changes: 3 additions & 3 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ import (

// initCmd represents the init command
var initCmd = &cobra.Command{
Use: "init",
Use: "init PROJECT_NAME",
Short: "Initialize an Oya project",
RunE: func(cmd *cobra.Command, args []string) error {
cwd, err := os.Getwd()
if err != nil {
return err
}
return internal.Init(cwd, cmd.OutOrStdout(), cmd.OutOrStderr())
return internal.Init(cwd, args[0], cmd.OutOrStdout(), cmd.OutOrStderr())
},
Args: cobra.NoArgs,
Args: cobra.ExactArgs(1),
}

func init() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/internal/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/tooploox/oya/pkg/raw"
)

func Init(rootDir string, stdout, stderr io.Writer) error {
err := raw.InitDir(rootDir)
func Init(rootDir, projectName string, stdout, stderr io.Writer) error {
err := raw.InitDir(rootDir, projectName)
if err != nil {
return errors.Wrapf(err, "Error while initializing %v", rootDir)
}
Expand Down
15 changes: 12 additions & 3 deletions features/init.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ Background:
Given I'm in project dir

Scenario: Init a project
When I run "oya init"
When I run "oya init OyaExample"
Then the command succeeds
And file ./Oyafile exists

Scenario: Init a existing project
When I run "oya init"
And I run "oya init"
When I run "oya init OyaExample"
And I run "oya init OyaExample2"
Then the command fails with error matching
"""
.*already an Oya project.*
"""

Scenario: Init a project name
When I run "oya init OyaExample"
Then the command succeeds
And file ./Oyafile contains
"""
Project: OyaExample
"""
5 changes: 3 additions & 2 deletions pkg/raw/init.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package raw

import (
"fmt"
"os"

"github.com/pkg/errors"
)

func InitDir(dirPath string) error {
func InitDir(dirPath, projectName string) error {
// BUG(bilus): Use raw access.
_, found, err := LoadFromDir(dirPath, dirPath)
if err == nil && found {
Expand All @@ -16,7 +17,7 @@ func InitDir(dirPath string) error {
if err != nil {
return err
}
_, err = f.WriteString("Project: project\n")
_, err = f.WriteString(fmt.Sprintf("Project: %s\n", projectName))
if err != nil {
_ = f.Close()
return err
Expand Down

0 comments on commit c6c3093

Please sign in to comment.