Skip to content

Commit

Permalink
build: 主要逻辑构建完毕(#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeyrce committed Apr 8, 2022
1 parent 1c7bdf1 commit 940f4c2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ _output/
.idea/
.DS_Store
skrctl
.skrctl/
53 changes: 23 additions & 30 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,6 @@ func mv(src, dst string) error {
return os.Rename(src, dst)
}

// 初始化项目 .skrctl 配置目录
func init() {
cwd, err := os.Getwd()
if err != nil {
fmt.Printf("初始化失败: %s\n", err.Error())
return
}
dir := path.Join(cwd, ".skrctl")
_, err = os.Stat(dir)
if err != nil {
if os.IsNotExist(err) {
err = os.Mkdir(dir, 0755)
if err == nil {
return
}
}
fmt.Printf("初始化失败: %s\n", err.Error())
return
}
}

func Add(services ...string) {
for _, s := range services {
if err := C.Add(s); err != nil {
Expand Down Expand Up @@ -157,6 +136,13 @@ type view struct {
}

func Status(services ...string) {
// 如果传入空,则展示所有已托管服务状态
if len(services) < 1 {
list := C.List()
for _, item := range list {
services = append(services, item.Name)
}
}
var views = make([]view, 0, len(services))
for _, s := range services {
if svc := C.Has(s); svc != nil {
Expand All @@ -182,7 +168,7 @@ func Start(services ...string) {
for _, s := range services {
svc := C.Has(s)
if svc == nil {
fmt.Printf("启动前需要先加入管理(skrctl add %s)\n", s)
fmt.Printf("操作前需要先加入管理(%s)\n", s)
continue
}
svc.Start()
Expand All @@ -191,26 +177,33 @@ func Start(services ...string) {

func Stop(services ...string) {
for _, s := range services {
if svc := C.Has(s); svc != nil {
svc.Stop()
svc := C.Has(s)
if svc == nil {
fmt.Printf("操作前需要先加入管理(%s)\n", s)
continue
}
svc.Stop()
}
}

func Enable(services ...string) {
for _, s := range services {
if svc := C.Has(s); svc != nil {
svc.SetAutoStart()
svc := C.Has(s)
if svc == nil {
fmt.Printf("操作前需要先加入管理(%s)\n", s)
continue
}
svc.SetAutoStart()
}

}

func Disable(services ...string) {
for _, s := range services {
if svc := C.Has(s); svc != nil {
svc.CloseAutoStart()
svc := C.Has(s)
if svc == nil {
fmt.Printf("操作前需要先加入管理(%s)\n", s)
continue
}
svc.CloseAutoStart()
}

}
7 changes: 5 additions & 2 deletions cmd/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ func newConf() *conf {
stat, err := os.Stat(dir)
if err != nil {
if os.IsNotExist(err) {
fmt.Println("未执行'skrctl init'")
os.Exit(1)
if err := os.Mkdir(dir, 0755); err != nil {
fmt.Println("初始化配置失败:", err.Error())
os.Exit(1)
}
return &c
}
fmt.Printf("加载本地配置失败: %s\n", err.Error())
os.Exit(1)
Expand Down

0 comments on commit 940f4c2

Please sign in to comment.