Refactor cli (#329)

- move cli files from `cli/drone` to `cli/`
- move cli main to `cmd/cli/main.go` to match agent and server
- use version from `version/version.go` to match agent and server
This commit is contained in:
Anbraten 2021-09-21 16:36:41 +02:00 committed by GitHub
parent ac46ee9345
commit 188b9e6eb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
51 changed files with 69 additions and 124 deletions

2
.gitignore vendored
View file

@ -33,7 +33,7 @@ docker-compose.yml
/.env /.env
extras/ extras/
release/ release/
build/ /build/
cli/release/ cli/release/
server/swagger/files/*.json server/swagger/files/*.json

View file

@ -74,17 +74,17 @@ release-cli:
# disable CGO for cross-compiling # disable CGO for cross-compiling
export CGO_ENABLED=0 export CGO_ENABLED=0
# compile for all architectures # compile for all architectures
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=${DRONE_TAG##v}" -o cli/release/linux/amd64/woodpecker github.com/woodpecker-ci/woodpecker/cli/drone GOOS=linux GOARCH=amd64 go build -ldflags '${LDFLAGS}' -o cli/release/linux/amd64/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
GOOS=linux GOARCH=arm64 go build -ldflags "-X main.version=${DRONE_TAG##v}" -o cli/release/linux/arm64/woodpecker github.com/woodpecker-ci/woodpecker/cli/drone GOOS=linux GOARCH=arm64 go build -ldflags '${LDFLAGS}' -o cli/release/linux/arm64/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
GOOS=linux GOARCH=arm go build -ldflags "-X main.version=${DRONE_TAG##v}" -o cli/release/linux/arm/woodpecker github.com/woodpecker-ci/woodpecker/cli/drone GOOS=linux GOARCH=arm go build -ldflags '${LDFLAGS}' -o cli/release/linux/arm/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
GOOS=windows GOARCH=amd64 go build -ldflags "-X main.version=${DRONE_TAG##v}" -o cli/release/windows/amd64/woodpecker github.com/woodpecker-ci/woodpecker/cli/drone GOOS=windows GOARCH=amd64 go build -ldflags '${LDFLAGS}' -o cli/release/windows/amd64/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.version=${DRONE_TAG##v}" -o cli/release/darwin/amd64/woodpecker github.com/woodpecker-ci/woodpecker/cli/drone GOOS=darwin GOARCH=amd64 go build -ldflags '${LDFLAGS}' -o cli/release/darwin/amd64/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
# tar binary files prior to upload # tar binary files prior to upload
tar -cvzf cli/release/woodpecker_linux_amd64.tar.gz -C cli/release/linux/amd64 woodpecker tar -cvzf cli/release/woodpecker_linux_amd64.tar.gz -C cli/release/linux/amd64 woodpecker-cli
tar -cvzf cli/release/woodpecker_linux_arm64.tar.gz -C cli/release/linux/arm64 woodpecker tar -cvzf cli/release/woodpecker_linux_arm64.tar.gz -C cli/release/linux/arm64 woodpecker-cli
tar -cvzf cli/release/woodpecker_linux_arm.tar.gz -C cli/release/linux/arm woodpecker tar -cvzf cli/release/woodpecker_linux_arm.tar.gz -C cli/release/linux/arm woodpecker-cli
tar -cvzf cli/release/woodpecker_windows_amd64.tar.gz -C cli/release/windows/amd64 woodpecker tar -cvzf cli/release/woodpecker_windows_amd64.tar.gz -C cli/release/windows/amd64 woodpecker-cli
tar -cvzf cli/release/woodpecker_darwin_amd64.tar.gz -C cli/release/darwin/amd64 woodpecker tar -cvzf cli/release/woodpecker_darwin_amd64.tar.gz -C cli/release/darwin/amd64 woodpecker-cli
# generate shas for tar files # generate shas for tar files
sha256sum cli/release/*.tar.gz > cli/release/woodpecker_checksums.txt sha256sum cli/release/*.tar.gz > cli/release/woodpecker_checksums.txt

View file

@ -1,57 +0,0 @@
workspace:
base: /go
path: src/github.com/drone/drone-cli
pipeline:
build:
image: golang:1.9
commands: sh .drone.sh
publish_latest:
image: plugins/docker
repo: drone/cli
secrets: [docker_username, docker_password]
auto_tag: true
when:
event: [push, tag]
publish_alpine:
image: plugins/docker
repo: drone/cli
secrets: [docker_username, docker_password]
auto_tag: true
auto_tag_suffix: alpine
dockerfile: Dockerfile.alpine
when:
event: [push, tag]
publish_linux_arm:
image: plugins/docker
repo: drone/cli
secrets: [docker_username, docker_password]
auto_tag: true
auto_tag_suffix: linux-arm
dockerfile: Dockerfile.linux.arm
when:
event: [push, tag]
publish_linux_arm64:
image: plugins/docker
repo: drone/cli
secrets: [docker_username, docker_password]
auto_tag: true
auto_tag_suffix: linux-arm64
dockerfile: Dockerfile.linux.arm64
when:
event: [push, tag]
release:
image: plugins/github-release
files:
- release/woodpecker_*.tar.gz
- release/woodpecker_checksums.txt
secrets:
- source: github_token
target: github_release_api_key
when:
event: tag

View file

@ -1 +1,5 @@
Command line client for the Drone continuous integration server. Please see the official documentation at http://docs.drone.io/cli-installation/ # Woodpecker CLI
Command line client for the Woodpecker continuous integration server.
Please see the official documentation at https://woodpecker-ci.github.io/docs/cli

View file

@ -5,7 +5,7 @@ import (
"strconv" "strconv"
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var buildApproveCmd = cli.Command{ var buildApproveCmd = cli.Command{

View file

@ -5,7 +5,7 @@ import (
"strconv" "strconv"
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var buildDeclineCmd = cli.Command{ var buildDeclineCmd = cli.Command{

View file

@ -6,7 +6,7 @@ import (
"text/template" "text/template"
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var buildInfoCmd = cli.Command{ var buildInfoCmd = cli.Command{

View file

@ -5,7 +5,7 @@ import (
"strconv" "strconv"
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var buildKillCmd = cli.Command{ var buildKillCmd = cli.Command{

View file

@ -5,7 +5,7 @@ import (
"text/template" "text/template"
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var buildLastCmd = cli.Command{ var buildLastCmd = cli.Command{

View file

@ -5,7 +5,7 @@ import (
"text/template" "text/template"
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var buildListCmd = cli.Command{ var buildListCmd = cli.Command{

View file

@ -6,7 +6,7 @@ import (
"text/template" "text/template"
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var buildPsCmd = cli.Command{ var buildPsCmd = cli.Command{

View file

@ -6,7 +6,7 @@ import (
"text/template" "text/template"
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var buildQueueCmd = cli.Command{ var buildQueueCmd = cli.Command{

View file

@ -6,7 +6,7 @@ import (
"strconv" "strconv"
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var buildStartCmd = cli.Command{ var buildStartCmd = cli.Command{

View file

@ -5,7 +5,7 @@ import (
"strconv" "strconv"
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var buildStopCmd = cli.Command{ var buildStopCmd = cli.Command{

View file

@ -6,7 +6,7 @@ import (
"os" "os"
"strconv" "strconv"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
"github.com/woodpecker-ci/woodpecker/drone-go/drone" "github.com/woodpecker-ci/woodpecker/drone-go/drone"
"github.com/urfave/cli" "github.com/urfave/cli"

View file

@ -6,7 +6,7 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
// Command exports the info command. // Command exports the info command.

View file

@ -5,7 +5,7 @@ import (
"strconv" "strconv"
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var logPurgeCmd = cli.Command{ var logPurgeCmd = cli.Command{

View file

@ -4,7 +4,7 @@ import (
"io/ioutil" "io/ioutil"
"strings" "strings"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
"github.com/woodpecker-ci/woodpecker/drone-go/drone" "github.com/woodpecker-ci/woodpecker/drone-go/drone"
"github.com/urfave/cli" "github.com/urfave/cli"

View file

@ -4,7 +4,7 @@ import (
"html/template" "html/template"
"os" "os"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
"github.com/urfave/cli" "github.com/urfave/cli"
) )

View file

@ -6,7 +6,7 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var registryListCmd = cli.Command{ var registryListCmd = cli.Command{

View file

@ -1,7 +1,7 @@
package registry package registry
import ( import (
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
"github.com/urfave/cli" "github.com/urfave/cli"
) )

View file

@ -4,7 +4,7 @@ import (
"io/ioutil" "io/ioutil"
"strings" "strings"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
"github.com/woodpecker-ci/woodpecker/drone-go/drone" "github.com/woodpecker-ci/woodpecker/drone-go/drone"
"github.com/urfave/cli" "github.com/urfave/cli"

View file

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var repoAddCmd = cli.Command{ var repoAddCmd = cli.Command{

View file

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var repoChownCmd = cli.Command{ var repoChownCmd = cli.Command{

View file

@ -5,7 +5,7 @@ import (
"text/template" "text/template"
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var repoInfoCmd = cli.Command{ var repoInfoCmd = cli.Command{

View file

@ -5,7 +5,7 @@ import (
"text/template" "text/template"
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var repoListCmd = cli.Command{ var repoListCmd = cli.Command{

View file

@ -2,7 +2,7 @@ package repo
import ( import (
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var repoRepairCmd = cli.Command{ var repoRepairCmd = cli.Command{

View file

@ -3,7 +3,7 @@ package repo
import ( import (
"fmt" "fmt"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
"github.com/urfave/cli" "github.com/urfave/cli"
) )

View file

@ -5,7 +5,7 @@ import (
"text/template" "text/template"
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var repoSyncCmd = cli.Command{ var repoSyncCmd = cli.Command{

View file

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
"github.com/woodpecker-ci/woodpecker/drone-go/drone" "github.com/woodpecker-ci/woodpecker/drone-go/drone"
"github.com/urfave/cli" "github.com/urfave/cli"

View file

@ -4,7 +4,7 @@ import (
"io/ioutil" "io/ioutil"
"strings" "strings"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
"github.com/woodpecker-ci/woodpecker/drone-go/drone" "github.com/woodpecker-ci/woodpecker/drone-go/drone"
"github.com/urfave/cli" "github.com/urfave/cli"

View file

@ -6,7 +6,7 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var secretInfoCmd = cli.Command{ var secretInfoCmd = cli.Command{

View file

@ -7,7 +7,7 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var secretListCmd = cli.Command{ var secretListCmd = cli.Command{

View file

@ -3,7 +3,7 @@ package secret
import ( import (
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var secretDeleteCmd = cli.Command{ var secretDeleteCmd = cli.Command{

View file

@ -4,7 +4,7 @@ import (
"io/ioutil" "io/ioutil"
"strings" "strings"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
"github.com/woodpecker-ci/woodpecker/drone-go/drone" "github.com/woodpecker-ci/woodpecker/drone-go/drone"
"github.com/urfave/cli" "github.com/urfave/cli"

View file

@ -6,7 +6,7 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/drone-go/drone" "github.com/woodpecker-ci/woodpecker/drone-go/drone"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var userAddCmd = cli.Command{ var userAddCmd = cli.Command{

View file

@ -7,7 +7,7 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var userInfoCmd = cli.Command{ var userInfoCmd = cli.Command{

View file

@ -6,7 +6,7 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var userListCmd = cli.Command{ var userListCmd = cli.Command{

View file

@ -5,7 +5,7 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/woodpecker-ci/woodpecker/cli/drone/internal" "github.com/woodpecker-ci/woodpecker/cli/internal"
) )
var userRemoveCmd = cli.Command{ var userRemoveCmd = cli.Command{

View file

@ -4,57 +4,55 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/woodpecker-ci/woodpecker/cli/drone/build" "github.com/woodpecker-ci/woodpecker/cli/build"
"github.com/woodpecker-ci/woodpecker/cli/drone/deploy" "github.com/woodpecker-ci/woodpecker/cli/deploy"
"github.com/woodpecker-ci/woodpecker/cli/drone/exec" "github.com/woodpecker-ci/woodpecker/cli/exec"
"github.com/woodpecker-ci/woodpecker/cli/drone/info" "github.com/woodpecker-ci/woodpecker/cli/info"
"github.com/woodpecker-ci/woodpecker/cli/drone/log" "github.com/woodpecker-ci/woodpecker/cli/log"
"github.com/woodpecker-ci/woodpecker/cli/drone/registry" "github.com/woodpecker-ci/woodpecker/cli/registry"
"github.com/woodpecker-ci/woodpecker/cli/drone/repo" "github.com/woodpecker-ci/woodpecker/cli/repo"
"github.com/woodpecker-ci/woodpecker/cli/drone/secret" "github.com/woodpecker-ci/woodpecker/cli/secret"
"github.com/woodpecker-ci/woodpecker/cli/drone/user" "github.com/woodpecker-ci/woodpecker/cli/user"
"github.com/woodpecker-ci/woodpecker/version"
_ "github.com/joho/godotenv/autoload" _ "github.com/joho/godotenv/autoload"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
// drone version number
var version string
func main() { func main() {
app := cli.NewApp() app := cli.NewApp()
app.Name = "drone" app.Name = "woodpecker-cli"
app.Version = version app.Version = version.String()
app.Usage = "command line utility" app.Usage = "command line utility"
app.EnableBashCompletion = true app.EnableBashCompletion = true
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
cli.StringFlag{ cli.StringFlag{
EnvVar: "DRONE_TOKEN,WOODPECKER_TOKEN",
Name: "t, token", Name: "t, token",
Usage: "server auth token", Usage: "server auth token",
EnvVar: "DRONE_TOKEN,WOODPECKER_TOKEN",
}, },
cli.StringFlag{ cli.StringFlag{
EnvVar: "DRONE_SERVER,WOODPECKER_SERVER",
Name: "s, server", Name: "s, server",
Usage: "server address", Usage: "server address",
EnvVar: "DRONE_SERVER,WOODPECKER_SERVER",
}, },
cli.BoolFlag{ cli.BoolFlag{
Name: "skip-verify",
Usage: "skip ssl verfification",
EnvVar: "DRONE_SKIP_VERIFY,WOODPECKER_SKIP_VERIFY", EnvVar: "DRONE_SKIP_VERIFY,WOODPECKER_SKIP_VERIFY",
Name: "skip-verify",
Usage: "skip ssl verification",
Hidden: true, Hidden: true,
}, },
cli.StringFlag{ cli.StringFlag{
EnvVar: "SOCKS_PROXY",
Name: "socks-proxy", Name: "socks-proxy",
Usage: "socks proxy address", Usage: "socks proxy address",
EnvVar: "SOCKS_PROXY",
Hidden: true, Hidden: true,
}, },
cli.BoolFlag{ cli.BoolFlag{
EnvVar: "SOCKS_PROXY_OFF",
Name: "socks-proxy-off", Name: "socks-proxy-off",
Usage: "socks proxy ignored", Usage: "socks proxy ignored",
EnvVar: "SOCKS_PROXY_OFF",
Hidden: true, Hidden: true,
}, },
} }