Skip to content

Commit 1e94366

Browse files
committed
export clean_swift_scaffold pkg with runner command
1 parent 0de04bc commit 1e94366

5 files changed

Lines changed: 56 additions & 65 deletions

File tree

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Go](https://github.com/GeekTree0101/clean-swift-scaffold/actions/workflows/go.yml/badge.svg?branch=develop)](https://github.com/GeekTree0101/clean-swift-scaffold/actions/workflows/go.yml)
66

77

8-
### How to use?
8+
### Basic Usage
99

1010
<img height=300pt src="https://github.com/GeekTree0101/clean-swift-scaffold/blob/develop/res/example.png" />
1111

@@ -19,9 +19,29 @@ test_path: ./Playground/Tests // base test file destination
1919
indentation: 2 // indentation
2020
```
2121
22+
#### add clean_swift_scaffold runner command on your command
23+
```go
24+
var rootCmd = &cobra.Command{
25+
Use: "your cmd",
26+
Short: "your cmd short marty",
27+
Long: "your cmd long something",
28+
}
29+
30+
init() {
31+
rootCmd.AddCommand(clean_swift_scaffold.NewRunnerCommand("**use_name**"))
32+
}
33+
34+
func Execute() {
35+
if err := rootCmd.Execute(); err != nil {
36+
fmt.Fprintln(os.Stderr, err)
37+
os.Exit(1)
38+
}
39+
}
40+
```
41+
2242
#### run
2343
```sh
24-
clean-swift-scaffold run -n Feed -u Fetch,Delete,Update
44+
your_command **use_name** -n Feed -u Fetch,Delete,Update
2545
```
2646

2747
flag list

cmd/logo.go

Lines changed: 0 additions & 22 deletions
This file was deleted.

cmd/root.go

Lines changed: 0 additions & 21 deletions
This file was deleted.

main.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

cmd/gen.go renamed to runner.go

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cmd
1+
package clean_swift_scaffold
22

33
import (
44
"fmt"
@@ -7,9 +7,37 @@ import (
77
"github.com/spf13/cobra"
88
)
99

10-
var (
11-
genCmd = &cobra.Command{
12-
Use: "run",
10+
const (
11+
logo = `
12+
_____ _ _____ _ __ _
13+
/ __ \ | / ___| (_)/ _| |
14+
| / \/ | ___ __ _ _ __ \ '--.__ ___| |_| |_
15+
| | | |/ _ \/ _' | '_ \ '--. \ \ /\ / / | _| __|
16+
| \__/\ | __/ (_| | | | /\__/ /\ V V /| | | | |_
17+
\____/_|\___|\__,_|_| |_\____/ \_/\_/ |_|_| \__|
18+
19+
20+
_____ __ __ _ _
21+
/ ___| / _|/ _| | | | |
22+
\ '--. ___ __ _| |_| |_ ___ | | __| |
23+
'--. \/ __/ _' | _| _/ _ \| |/ _' |
24+
/\__/ / (_| (_| | | | || (_) | | (_| |
25+
\____/ \___\__,_|_| |_| \___/|_|\__._|
26+
27+
Copyright © 2021 Geektree0101. All rights reserved.
28+
`
29+
)
30+
31+
func NewRunnerCommand(use string) *cobra.Command {
32+
33+
var name string
34+
var usecasesString string
35+
var sourceDir string
36+
var testDir string
37+
var configFilePath string
38+
39+
genCmd := &cobra.Command{
40+
Use: use,
1341
Short: "generate source & unit tests files",
1442
Run: func(cmd *cobra.Command, args []string) {
1543

@@ -40,19 +68,13 @@ var (
4068

4169
},
4270
}
43-
name string
44-
usecasesString string
45-
sourceDir string
46-
testDir string
47-
configFilePath string
48-
)
4971

50-
func init() {
5172
genCmd.Flags().StringVarP(&name, "name", "n", "", "Usecase name, ex: -n Detail or --name Detail")
5273
genCmd.Flags().StringVarP(&usecasesString, "usecases", "u", "", "Behavior names, ex: -u Reload,Next or --usecases Reload,Next")
5374
genCmd.Flags().StringVarP(&configFilePath, "config", "c", "./config.yaml", "Configure file path, ex: -t ./some/config.yaml or --test ./some/config.yaml")
5475
// optional flags
5576
genCmd.Flags().StringVarP(&sourceDir, "source", "s", "", "Source dir, ex: -s ./Projects or --source ./Projects")
5677
genCmd.Flags().StringVarP(&testDir, "test", "t", "", "Test dir, ex: -t ./Projects or --test ./Projects")
57-
rootCmd.AddCommand(genCmd)
78+
79+
return genCmd
5880
}

0 commit comments

Comments
 (0)