Skip to content

Commit 64bcab6

Browse files
committed
#9 Complete Action:Util
1 parent f2b0483 commit 64bcab6

File tree

12 files changed

+653
-12
lines changed

12 files changed

+653
-12
lines changed

README.md

Lines changed: 101 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,58 @@
11
# README
22

3-
## fluent cli
3+
## Build and Deploy to Local
4+
5+
```shell
6+
sh deploy-local.sh
7+
```
8+
9+
## fluent cli help
10+
11+
```shell
12+
❯ fluent -h
13+
fluent cli is a collection of daily scripts
14+
15+
Usage:
16+
fluent [flags]
17+
fluent [command]
18+
19+
Examples:
20+
fluent <category> <action> <--options>
21+
22+
Available Commands:
23+
completion Generate the autocompletion script for the specified shell
24+
help Help about any command
25+
issue Create a new issue
26+
starter fluent start java,go,ts-lib,fe-next,mono,python
27+
util fluent util echo,mac-cleanup
28+
29+
Flags:
30+
-h, --help help for fluent
31+
-v, --version version for fluent
32+
33+
Use "fluent [command] --help" for more information about a command.
34+
35+
```
36+
37+
## fluent starer cli
38+
39+
create template project: ***fluent starter <name>***
40+
41+
```shell
42+
fluent starter -h
43+
44+
45+
Usage:
46+
fluent starter [flags]
47+
48+
Examples:
49+
fluent start java
50+
51+
Flags:
52+
-h, --help help for starter
53+
54+
```
455

5-
- create template project
656
```shell
757
fluent starter -h
858
fluent starter java
@@ -12,6 +62,54 @@ fluent starter ts-lib
1262
fluent starter mono
1363
```
1464

65+
## fluent util cli
66+
67+
***fluent util <cmd>***, to run ,and add more commands in utils.json file
68+
69+
```shell
70+
fluent util echo,mac-cleanup
71+
72+
Usage:
73+
fluent util [flags]
74+
75+
Examples:
76+
fluent util echo
77+
78+
Flags:
79+
-h, --help help for util
80+
81+
```
82+
83+
## action json file
84+
85+
action structure:
86+
- name: command name
87+
- desc: command usage
88+
- commands: a list of shell commands or something else which is runnable
89+
90+
```json
91+
{
92+
"actions": [
93+
{
94+
"name": "echo",
95+
"desc": "try cli",
96+
"commands": [
97+
"echo \"hello fluent cli\""
98+
]
99+
}, {
100+
"name": "mac-cleanup",
101+
"desc": "cleanup mac pc to free disk space",
102+
"commands": [
103+
"sh mac-cleanup.sh"
104+
]
105+
}
106+
]
107+
}
108+
```
109+
110+
111+
112+
15113
## Pocketbase Server
16114

17115
```shell
@@ -24,7 +122,7 @@ All Url:
24122
- http://127.0.0.1:8090/_/ - Admin dashboard UI
25123
- http://127.0.0.1:8090/api/ - REST API
26124

27-
## Embedded PocketServer
125+
28126

29127
### References
30128

cmd/actions/base.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package actions
2+
3+
import (
4+
"github.com/fluent-qa/qgops/internal/utils/shell"
5+
"github.com/spf13/cobra"
6+
"path"
7+
"strings"
8+
)
9+
10+
func CreateActions(actionCategory, actionConfigFile string) ([]string, *cobra.Command) {
11+
usedActions := shell.LoadCommands(path.Join(WorkSpaceDir, actionConfigFile))
12+
13+
availableActions := usedActions.GetAvailableActionNames()
14+
availableCmd := &cobra.Command{
15+
Use: actionCategory,
16+
Short: "fluent " + actionCategory + " " + strings.Join(availableActions, ","),
17+
Long: "fluent " + actionCategory + " " + strings.Join(availableActions, ","),
18+
Example: "fluent " + actionCategory + " " + availableActions[0],
19+
ValidArgs: availableActions,
20+
//ValidArgsFunction: ;
21+
//RunE
22+
Run: func(cmd *cobra.Command, args []string) {
23+
category := args[0]
24+
usedActions.ExecuteActionByName(category)
25+
},
26+
}
27+
return availableActions, availableCmd
28+
}

cmd/actions/constants.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package actions
2+
3+
import "os"
4+
5+
var WorkSpaceDir = os.Getenv("FLUENT_HOME")

cmd/actions/starter.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@ package actions
22

33
import (
44
_ "log/slog"
5-
"os"
65
"path"
76
"strings"
87

98
"github.com/fluent-qa/qgops/internal/utils/shell"
109
"github.com/spf13/cobra"
1110
)
1211

13-
var CurrentDir = os.Getenv("FLUENT_HOME")
14-
15-
var starterActions = shell.LoadCommands(path.Join(CurrentDir, "starters.json"))
12+
var starterActions = shell.LoadCommands(path.Join(WorkSpaceDir, "starters.json"))
1613

1714
var (
1815
AvailableStarter = starterActions.GetAvailableActionNames()

cmd/actions/utility.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package actions
2+
3+
var (
4+
_, UtilCmd = CreateActions("util", "utils.json")
5+
)

cmd/base/root.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ package base
22

33
import (
44
"github.com/spf13/cobra"
5-
"os"
65
)
76

87
var VERSION = "0.0.2"
9-
var WorkSpaceDir = os.Getenv("FLUENT_HOME")
108

119
var CmdRoot = &cobra.Command{
1210
Use: "fluent",
1311
Example: "fluent <category> <action> <--options>",
14-
Short: "fluent is for feeds usage",
12+
Short: "fluent cli is a collection of daily scripts",
1513
Version: VERSION,
1614
RunE: func(cmd *cobra.Command, args []string) error {
1715
return cmd.Help()

cmd/fluent.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
func init() {
99
base.CmdRoot.AddCommand(actions.StarterCmd)
1010
base.CmdRoot.AddCommand(actions.IssueCmd)
11+
base.CmdRoot.AddCommand(actions.UtilCmd)
1112
}
1213
func main() {
1314
_ = base.CmdRoot.Execute()

deploy-local.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
make build-cli
22
mv fluent ~/workspace/tools/bin
33
cp starters.json ~/workspace/tools/bin
4+
cp utils.json ~/workspace/tools/bin
5+
cp scripts/mac-cleanup.sh ~/workspace/tools/bin
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Starter: Create Project by given project name
2+
3+
```shell
4+
fluent starter -t fe-next -p new-name
5+
```
6+
7+
-t: template name
8+
-p: new project name

internal/utils/shell/commands.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package shell
22

33
import (
44
"io"
5-
"log"
65
"log/slog"
76
"os"
87

@@ -29,7 +28,7 @@ var NotFoundAction = &NamedAction{
2928
func ExecShellCommand(cmd string) (int, error) {
3029
return Exec(cmd).
3130
FilterScan(func(s string, writer io.Writer) {
32-
log.Println(s)
31+
slog.Info(s)
3332
}).Stdout()
3433
}
3534

0 commit comments

Comments
 (0)