Skip to content

Commit

Permalink
fea: auto command
Browse files Browse the repository at this point in the history
  • Loading branch information
Lanly109 committed Oct 8, 2024
1 parent 4ae1ea3 commit 6113213
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

## 更新日志

### 2024.10.8

- 新增`auto`指令,一键执行整个流程,即`clean -> check -> valid -> md5`
- 更新`倒计时html模版`

### 2023.2.26

- `time`命令更名为`valid`命令,新增`SourceSizeLimit`参数,在检查时间戳的基础上追加代码文件大小检查
Expand Down Expand Up @@ -121,6 +126,10 @@ chmod +x lan
# 生成配置文件,并修改
./lan gen config

# 一键执行
./lan auto
# 或者依次执行以下步骤

# 清理无关文件
./lan clean
# 检查成员名单
Expand All @@ -129,6 +138,7 @@ chmod +x lan
./lan md5
# 检查文件修改时间和文件大小
./lan valid

# 查重
./lan moss
```
Expand Down Expand Up @@ -161,6 +171,14 @@ chmod +x lan

后续指令默认读取`config.toml`配置文件,如需更改,可接`--config=<name>`参数自定义读取配置文件

### 一键执行

```bash
./lan auto
```

此命令将依次执行`clean -> check -> valid -> md5`指令,配置读取推荐为配置文件。

### 清理无关文件

```bash
Expand Down
56 changes: 56 additions & 0 deletions cmd/auto.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright © 2022 Lanly
*/
package cmd

import (
"bufio"
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
)

// checkCmd represents the check command
var autoCmd = &cobra.Command{
Use: "auto",
Short: "one command to run all",
Long: `clean -> check -> valid -> md5`,
Run: func(cmd *cobra.Command, args []string) {
commands := []*cobra.Command{cleanCmd, checkCmd, validCmd, md5Cmd}

reader := bufio.NewReader(os.Stdin)

for _, command := range commands {
fmt.Printf("\nPress Enter to run '%s', or type anything else to stop...\n", command.Name())
input, err := reader.ReadString('\n')
if err != nil {
fmt.Println("Error reading input:", err)
return
}

// Trim any extra whitespace, and check if it's a plain Enter
if strings.TrimSpace(input) != "" {
fmt.Println("Stopping execution.")
return
}

// Execute the command if Enter is pressed
new_args := []string{command.Name()}
if len(args) > 1 {
new_args = append(new_args, args[1:]...)
}
rootCmd.SetArgs(new_args)
if err := rootCmd.Execute(); err != nil {
fmt.Printf("Error executing '%s': %v\n", command.Name(), err)
return
}
}

},
}

func init() {
rootCmd.AddCommand(autoCmd)
}

0 comments on commit 6113213

Please sign in to comment.