Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
tiechui1994 committed Sep 22, 2021
1 parent 004a365 commit 600e76a
Show file tree
Hide file tree
Showing 4 changed files with 378 additions and 379 deletions.
116 changes: 0 additions & 116 deletions aliyun/common.go

This file was deleted.

171 changes: 0 additions & 171 deletions aliyun/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ import (
"fmt"
"os"
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
"sync"
"text/template"

"github.com/urfave/cli"

"github.com/tiechui1994/tool/util"
)

Expand Down Expand Up @@ -654,170 +650,3 @@ func (p *ProjectFs) Cwd(dir string) error {
func (p *ProjectFs) Pwd() {
fmt.Println(p.pwd)
}

func Exec() cli.Command {
Setup()

cmd := cli.Command{
Name: "project",
Description: "aliyun teambition management",
}

cmd.Subcommands = []cli.Command{
{
Name: "pwd",
Usage: "current dir",
Action: func(c *cli.Context) error {
fmt.Println("pwd")
return nil
},
},
{
Name: "cd",
Usage: "change to dir",
ArgsUsage: "[DIR]",
Action: func(c *cli.Context) error {
fmt.Println("cd")
return nil
},
},
{
Name: "ls",
Aliases: []string{"list"},
Usage: "list files or dirs in the dir",
ArgsUsage: "[DIR]",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "d",
Usage: "only include dirs",
},
cli.BoolFlag{
Name: "f",
Usage: "only include files",
},
cli.BoolFlag{
Name: "a",
Usage: "include files and dirs",
},
},
Action: func(c *cli.Context) error {
fmt.Println("ls", c.Bool("a"))

for i := 0; i < c.NArg(); i++ {
fmt.Println(c.Args().Get(i))
}

return nil
},
},
{
Name: "upload",
Usage: "upload file to project",
ArgsUsage: "[LOCAL] [REMOTE]",
Action: func(c *cli.Context) error {
return nil
},
},
{
Name: "mv",
Aliases: []string{"move"},
Usage: "move file or dir to dir",
ArgsUsage: "[SRC] [DST]",
Action: func(c *cli.Context) error {
return nil
},
},
{
Name: "cp",
Aliases: []string{"copy"},
Usage: "copy dir or file",
ArgsUsage: "[SRC] [DST]",
Action: func(c *cli.Context) error {
return nil
},
},
{
Name: "rm",
Aliases: []string{"remove"},
Usage: "remove dir or file",
ArgsUsage: "[NAME]",
Action: func(c *cli.Context) error {
return nil
},
},
{
Name: "rename",
Usage: "rename dir or file",
ArgsUsage: "[SRCNAME] [DSTNAME]",
Action: func(c *cli.Context) error {
return nil
},
},
}

return cmd
}

func Setup() *ProjectFs {
AutoLogin()

_, orgs, err := GetCacheData()
if err != nil {
fmt.Println("catch data err", err)
os.Exit(1)
}

tpl := `
{{ range $orgidx, $ele := . }}
{{ printf "%d org: %s(%s)" $orgidx .Name .OrganizationId -}}
{{ range $pidx, $val := .Projects }}
{{ printf "%d.%d project: %s(%s)" $orgidx $pidx .Name .ProjectId -}}
{{ end }}
{{ end }}
`

tpl = strings.Trim(tpl, "\n")
temp, err := template.New("").Parse(tpl)
if err != nil {
os.Exit(1)
}

var buf bytes.Buffer
err = temp.Execute(&buf, orgs)
if err != nil {
os.Exit(1)
}
fmt.Println(buf.String())

reindex := regexp.MustCompile(`^([0-9])\.([0-9])$`)
retry:
var idx string
fmt.Printf("Select project index:")
fmt.Scanf("%s", &idx)
if !reindex.MatchString(idx) {
fmt.Println("input fortmat error. eg: 0.1")
goto retry
}
tokens := reindex.FindAllStringSubmatch(idx, -1)
if len(tokens) == 0 || len(tokens[0]) != 3 {
fmt.Println("input fortmat error. eg: 0.1")
goto retry
}

id1, _ := strconv.Atoi(tokens[0][1])
id2, _ := strconv.Atoi(tokens[0][2])
if !(len(orgs) > id1 && len(orgs[id1].Projects) > id2) {
fmt.Println("input fortmat error. eg: 0.1")
goto retry
}

orgid := orgs[id1].OrganizationId
name := orgs[id1].Projects[id2].Name
p, err := NewProject(name, orgid)
if err != nil {
fmt.Println("new project err:", err)
os.Exit(1)
}

return p
}
Loading

0 comments on commit 600e76a

Please sign in to comment.