Skip to content

Commit 4b7b9ac

Browse files
committed
make project cmds more consitent
1 parent c4e3d4c commit 4b7b9ac

File tree

13 files changed

+60
-60
lines changed

13 files changed

+60
-60
lines changed

pkg/cmd/prj/add.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package prj
2+
3+
import (
4+
"github.com/apigear-io/cli/pkg/prj"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
func NewAddCommand() *cobra.Command {
10+
var prjDir string
11+
var cmd = &cobra.Command{
12+
Use: "add doc-type doc-name",
13+
Short: "add document to project",
14+
Long: `add document to project from a template.`,
15+
Args: cobra.ExactArgs(2),
16+
RunE: func(cmd *cobra.Command, args []string) error {
17+
docType := args[0]
18+
name := args[1]
19+
target, err := prj.AddDocument(prjDir, docType, name)
20+
if err != nil {
21+
return err
22+
}
23+
cmd.Printf("document %s created\n", target)
24+
return nil
25+
},
26+
}
27+
cmd.Flags().StringVarP(&prjDir, "project", "p", ".", "project directory")
28+
return cmd
29+
}

pkg/cmd/prj/create.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
package prj
22

33
import (
4+
"github.com/apigear-io/cli/pkg/log"
45
"github.com/apigear-io/cli/pkg/prj"
56

67
"github.com/spf13/cobra"
78
)
89

9-
func NewCreateCommand() *cobra.Command {
10-
var prjDir string
10+
// CreateProjectCommand returns a new cobra.Command for the "init" command.
11+
func CreateProjectCommand() *cobra.Command {
12+
var dir string
1113
var cmd = &cobra.Command{
12-
Use: "create doc-type doc-name",
13-
Short: "Create a new document inside current project",
14-
Long: `Create a new document inside current project from a template.`,
15-
Args: cobra.ExactArgs(2),
14+
Use: "create",
15+
Short: "create new project",
16+
Long: `create new project with default project files`,
17+
Args: cobra.NoArgs,
1618
RunE: func(cmd *cobra.Command, args []string) error {
17-
docType := args[0]
18-
name := args[1]
19-
target, err := prj.CreateProjectDocument(prjDir, docType, name)
19+
log.Debug().Msgf("create project in %s", dir)
20+
info, err := prj.InitProject(dir)
2021
if err != nil {
2122
return err
2223
}
23-
cmd.Printf("document %s created\n", target)
24+
cmd.Printf("project created at: %s\n", info.Path)
2425
return nil
2526
},
2627
}
27-
cmd.Flags().StringVarP(&prjDir, "project", "p", ".", "project directory")
28+
cmd.Flags().StringVarP(&dir, "dir", "d", ".", "project directory to create")
29+
cmd.MarkFlagRequired("dir")
2830
return cmd
2931
}

pkg/cmd/prj/edit.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
func NewEditCommand() *cobra.Command {
1111
var cmd = &cobra.Command{
1212
Use: "edit",
13-
Short: "Edit a project in the default editor (vscode)",
14-
Long: `Edit a project in the default editor (e.g.Visual Studio Code).`,
13+
Short: "open project in editor",
14+
Long: `open project in the default editor (e.g.Visual Studio Code).`,
1515
Args: cobra.ExactArgs(1),
1616
RunE: func(cmd *cobra.Command, args []string) error {
1717
dir := args[0]

pkg/cmd/prj/import.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ func NewImportCommand() *cobra.Command {
1818
var target string
1919
var cmd = &cobra.Command{
2020
Use: "import source --target target",
21-
Short: "Import a remote project",
22-
Long: `Import a remote project from a repository to the local file system`,
21+
Short: "import a project",
22+
Long: `import a remote project from a repository to the local file system`,
2323
Args: cobra.ExactArgs(1),
2424
RunE: func(cmd *cobra.Command, args []string) error {
2525
source := args[0]

pkg/cmd/prj/info.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
func NewInfoCommand() *cobra.Command {
1111
var cmd = &cobra.Command{
1212
Use: "info",
13-
Short: "Display project information",
14-
Long: `Display detailed project information`,
13+
Short: "display project information",
14+
Long: `display detailed project information`,
1515
Args: cobra.ExactArgs(1),
1616
RunE: func(cmd *cobra.Command, args []string) error {
1717
dir := args[0]

pkg/cmd/prj/new.go

-31
This file was deleted.

pkg/cmd/prj/pack.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ func NewPackCommand() *cobra.Command {
1616
var dir string
1717
var cmd = &cobra.Command{
1818
Use: "pack",
19-
Short: "Pack a project",
20-
Long: `Pack the project and all files into a archive file`,
19+
Short: "pack project",
20+
Long: `pack the project and all files into a archive file for sharing`,
2121
Args: cobra.NoArgs,
2222
RunE: func(cmd *cobra.Command, args []string) error {
2323
dir, err := filepath.Abs(dir)

pkg/cmd/prj/recent.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
func NewRecentCommand() *cobra.Command {
1111
var cmd = &cobra.Command{
1212
Use: "recent",
13-
Short: "Display recent projects",
14-
Long: `Display recently used projects and their locations`,
13+
Short: "display recent projects",
14+
Long: `display recently used projects and their locations`,
1515
Args: cobra.NoArgs,
1616
RunE: func(cmd *cobra.Command, _ []string) error {
1717
cmd.Println("recent projects:")

pkg/cmd/prj/root.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ func NewRootCommand() *cobra.Command {
1212
Short: "Manage apigear projects",
1313
Long: `Projects consist of API descriptions, SDK configuration, simulation documents and other files`,
1414
}
15-
cmd.AddCommand(NewCreateCommand())
15+
cmd.AddCommand(NewAddCommand())
1616
cmd.AddCommand(NewEditCommand())
1717
cmd.AddCommand(NewImportCommand())
1818
cmd.AddCommand(NewInfoCommand())
19-
cmd.AddCommand(NewProjectCommand())
19+
cmd.AddCommand(CreateProjectCommand())
2020
cmd.AddCommand(NewOpenCommand())
2121
cmd.AddCommand(NewPackCommand())
2222
cmd.AddCommand(NewRecentCommand())

pkg/cmd/prj/share.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
func NewShareCommand() *cobra.Command {
99
var cmd = &cobra.Command{
1010
Use: "share",
11-
Short: "Share a project with your team",
12-
Long: `Share a project and all files with your team to work together`,
11+
Short: "share a project with your team (tbd)",
12+
Long: `share a project and all files with your team to work together (tbd)`,
1313
Args: cobra.ExactArgs(1),
1414
Run: func(cmd *cobra.Command, args []string) {
1515
dir := args[0]

pkg/cmd/tpl/create.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func NewCreateCommand() *cobra.Command {
1313
Short: "create new custom template",
1414
RunE: func(cmd *cobra.Command, args []string) error {
1515
cmd.Printf("create new template in %s with language %s support\n", dir, lang)
16-
return tpl.NewTemplate(dir, lang)
16+
return tpl.CreateCustomTemplate(dir, lang)
1717
},
1818
}
1919
cmd.Flags().StringVarP(&dir, "dir", "d", ".", "template directory to init")

pkg/prj/project.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ func PackProject(source string, target string) (string, error) {
147147
return target, nil
148148
}
149149

150-
// CreateDocument creates a new document inside the project
151-
func CreateProjectDocument(prjDir string, docType string, name string) (string, error) {
150+
// AddDocument creates a new document inside the project
151+
func AddDocument(prjDir string, docType string, name string) (string, error) {
152152
target := helper.Join(prjDir, "apigear", MakeDocumentName(docType, name))
153153
var err error
154154
switch docType {

pkg/tpl/new.go renamed to pkg/tpl/create.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/apigear-io/cli/pkg/helper"
1414
)
1515

16-
func NewTemplate(dir string, lang string) error {
16+
func CreateCustomTemplate(dir string, lang string) error {
1717
var rules []byte
1818
var apiTpl []byte
1919
var apiTplName string

0 commit comments

Comments
 (0)