From 8cb686144cfc1a72de1e4b6be877498be82890b9 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 3 Feb 2020 00:19:01 +0100 Subject: [PATCH] fix gitignore exclude --- .drone.star | 1 - .drone.yml | 3 +-- .gitignore | 2 +- cmd/url-parser/config.go | 56 ++++++++++++++++++++++++++++++++++++++++ cmd/url-parser/main.go | 27 +++++++++++++++++++ 5 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 cmd/url-parser/config.go create mode 100644 cmd/url-parser/main.go diff --git a/.drone.star b/.drone.star index b9ce03a..41bdaed 100644 --- a/.drone.star +++ b/.drone.star @@ -63,7 +63,6 @@ def binaries(arch): 'commands': [ '[ -z "${DRONE_TAG}" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}', 'mkdir -p release/', - "ls -lh", "xgo -ldflags \"-X main.Version=$BUILD_VERSION\" -tags netgo -targets 'linux/amd64,linux/arm-6,linux/arm64' -out url-parser-$BUILD_VERSION ./cmd/url-parser", 'cp /build/* release/' ] diff --git a/.drone.yml b/.drone.yml index 6e669d5..5585840 100644 --- a/.drone.yml +++ b/.drone.yml @@ -39,7 +39,6 @@ steps: commands: - "[ -z \"${DRONE_TAG}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}" - mkdir -p release/ - - ls -lh - xgo -ldflags "-X main.Version=$BUILD_VERSION" -tags netgo -targets 'linux/amd64,linux/arm-6,linux/arm64' -out url-parser-$BUILD_VERSION ./cmd/url-parser - cp /build/* release/ @@ -112,6 +111,6 @@ depends_on: --- kind: signature -hmac: 09c4c7b333827ec19925d9d33aae7c014f9dbfc8b35f2078419de0ba0a30c19a +hmac: 3c27762ebfb16c87206081475353f598923952f31bf58defe136a142c4dd0959 ... diff --git a/.gitignore b/.gitignore index 54cb485..a3742dd 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,4 @@ # Dependency directories (remove the comment below to include it) # vendor/ -url-parser +/url-parser diff --git a/cmd/url-parser/config.go b/cmd/url-parser/config.go new file mode 100644 index 0000000..66a543d --- /dev/null +++ b/cmd/url-parser/config.go @@ -0,0 +1,56 @@ +package main + +import ( + "github.com/urfave/cli/v2" + "github.com/xoxys/url-parser/commands" +) + +func globalFlags() []cli.Flag { + return []cli.Flag{ + &cli.StringFlag{ + Name: "url", + Usage: "source url to parse", + EnvVars: []string{"URL_PARSER_URL"}, + }, + } +} + +func configCommands() []*cli.Command { + return []*cli.Command{ + { + Name: "all", + Aliases: []string{"a"}, + Usage: "print out all parts from url", + Action: commands.Run, + Flags: globalFlags(), + }, + { + Name: "scheme", + Aliases: []string{"s"}, + Usage: "print out scheme from url", + Action: commands.Scheme, + Flags: globalFlags(), + }, + { + Name: "user", + Aliases: []string{"u"}, + Usage: "print out username from url", + Action: commands.User, + Flags: globalFlags(), + }, + { + Name: "password", + Aliases: []string{"p"}, + Usage: "print out password from url", + Action: commands.Password, + Flags: globalFlags(), + }, + { + Name: "path", + Aliases: []string{"pt"}, + Usage: "print out the path from url", + Action: commands.Path, + Flags: append(globalFlags(), commands.PathFlags()...), + }, + } +} diff --git a/cmd/url-parser/main.go b/cmd/url-parser/main.go new file mode 100644 index 0000000..54f11be --- /dev/null +++ b/cmd/url-parser/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "os" + + "github.com/sirupsen/logrus" + "github.com/urfave/cli/v2" + "github.com/xoxys/url-parser/commands" +) + +var ( + version = "0.1.0" +) + +func main() { + app := cli.NewApp() + app.Name = "url-parser" + app.Usage = "Parse URL and shows the part of it." + app.Version = version + app.Action = commands.Run + app.Flags = globalFlags() + app.Commands = configCommands() + + if err := app.Run(os.Args); err != nil { + logrus.Fatal(err) + } +}