2022-05-21 11:35:01 +08:00
|
|
|
// Package command ...
|
|
|
|
//
|
|
|
|
// Description : command ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 2022-05-20 22:34
|
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
2022-05-21 18:06:56 +08:00
|
|
|
|
|
|
|
"git.zhangdeman.cn/zhangdeman/command/define"
|
2022-05-21 11:35:01 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewLs ls命令
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 22:36 2022/5/20
|
|
|
|
func NewLs(workDir string) *ls {
|
|
|
|
return &ls{
|
|
|
|
workDir: workDir,
|
|
|
|
paramList: []string{"-l"},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type ls struct {
|
|
|
|
workDir string
|
|
|
|
paramList []string
|
|
|
|
isRecursive bool // 是否递归查询
|
|
|
|
}
|
|
|
|
|
|
|
|
// ShowHideFile 显示隐藏文件
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 22:38 2022/5/20
|
|
|
|
func (l *ls) ShowHideFile() *ls {
|
|
|
|
l.paramList = append(l.paramList, "-a")
|
|
|
|
return l
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recursive 递归查看所有目录下的文件
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 22:38 2022/5/20
|
|
|
|
func (l *ls) Recursive() *ls {
|
|
|
|
l.paramList = append(l.paramList, "-R")
|
|
|
|
return l
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run 执行命令
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 22:59 2022/5/20
|
|
|
|
func (l *ls) Run() (define.Result, []define.LsFileInfo) {
|
|
|
|
result := Execute(l.workDir, "ls", l.paramList)
|
|
|
|
if nil != result.Error {
|
|
|
|
return result, make([]define.LsFileInfo, 0)
|
|
|
|
}
|
|
|
|
resultStr := string(result.Output)
|
|
|
|
fileList := strings.Split(resultStr, "\t")
|
|
|
|
for _, item := range fileList {
|
|
|
|
if item == "." || item == ".." {
|
|
|
|
// 忽略 . 和 ..
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
fmt.Println(item)
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|