Skip to content

Commit

Permalink
restructure sub-packages
Browse files Browse the repository at this point in the history
  • Loading branch information
jpicht committed Mar 14, 2022
1 parent ea726af commit 7621ce6
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MULTI=$(shell ls cmd/multi)
SOURCES=$(shell find pkg internal -name \*.go)
SOURCES=$(shell find auth actions internal -name \*.go)

all: ${MULTI}
all: ${MULTI} azblob

${MULTI}: cmd/multi/$@ $(shell find cmd/multi -name \*.go) ${SOURCES}
go build ./cmd/multi/$@
Expand Down
2 changes: 1 addition & 1 deletion pkg/azcat/list.go → actions/list.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package azcat
package actions

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion pkg/azcat/log.go → actions/log.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package azcat
package actions

import "github.com/sirupsen/logrus"

Expand Down
2 changes: 1 addition & 1 deletion pkg/azcat/mode.go → actions/mode.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package azcat
package actions

import (
"reflect"
Expand Down
2 changes: 1 addition & 1 deletion pkg/azcat/read.go → actions/read.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package azcat
package actions

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion pkg/azcat/remove.go → actions/remove.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package azcat
package actions

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion pkg/azcat/run.go → actions/run.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package azcat
package actions

import "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"

Expand Down
2 changes: 1 addition & 1 deletion pkg/azcat/write.go → actions/write.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package azcat
package actions

import (
"context"
Expand Down
File renamed without changes.
File renamed without changes.
34 changes: 17 additions & 17 deletions cmd/azblob/guess.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@ import (
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/jpicht/azcat/pkg/azcat"
"github.com/jpicht/azcat/actions"
)

func getExplicitMode() azcat.Mode {
modes := []azcat.Mode{}
func getExplicitMode() actions.Mode {
modes := []actions.Mode{}

if *read {
modes = append(modes, azcat.EMode.List())
modes = append(modes, actions.EMode.List())
}

if *list {
modes = append(modes, azcat.EMode.List())
modes = append(modes, actions.EMode.List())
}

if *remove {
modes = append(modes, azcat.EMode.Remove())
modes = append(modes, actions.EMode.Remove())
}

if *write {
modes = append(modes, azcat.EMode.Write())
modes = append(modes, actions.EMode.Write())
}

if len(modes) == 0 {
return azcat.EMode.None()
return actions.EMode.None()
}

if len(modes) == 1 {
Expand All @@ -41,20 +41,20 @@ func getExplicitMode() azcat.Mode {
panic("unreachable")
}

func guessMode(blobUrl azblob.BlobURLParts, serviceClient *azblob.ServiceClient) azcat.Mode {
func guessMode(blobUrl azblob.BlobURLParts, serviceClient *azblob.ServiceClient) actions.Mode {
switch os.Args[0] {
case "azls":
return azcat.EMode.List()
return actions.EMode.List()
case "azcat":
return azcat.EMode.Read()
return actions.EMode.Read()
case "azput":
return azcat.EMode.Write()
return actions.EMode.Write()
case "azrm":
return azcat.EMode.Remove()
return actions.EMode.Remove()
}

if blobUrl.BlobName == "/" || blobUrl.BlobName == "" {
return azcat.EMode.List()
return actions.EMode.List()
}

blobClient := serviceClient.NewContainerClient(blobUrl.ContainerName).NewBlobClient(blobUrl.BlobName)
Expand All @@ -74,14 +74,14 @@ func guessMode(blobUrl azblob.BlobURLParts, serviceClient *azblob.ServiceClient)
}

if !exists {
return azcat.EMode.Write()
return actions.EMode.Write()
}

if !stdInIsPipe {
return azcat.EMode.Read()
return actions.EMode.Read()
}

return azcat.EMode.None()
return actions.EMode.None()
}

func isPipe(f *os.File) bool {
Expand Down
6 changes: 3 additions & 3 deletions cmd/azblob/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package main

import (
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/jpicht/azcat/actions"
"github.com/jpicht/azcat/internal"
"github.com/jpicht/azcat/pkg/azcat"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -36,9 +36,9 @@ func main() {

serviceClient := internal.GetClient(parsed)

if mode == azcat.EMode.None() {
if mode == actions.EMode.None() {
mode = guessMode(parsed, serviceClient)
}

azcat.Run(mode, parsed, serviceClient)
actions.Run(mode, parsed, serviceClient)
}
4 changes: 2 additions & 2 deletions cmd/multi/azcat/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"github.com/jpicht/azcat/actions"
"github.com/jpicht/azcat/internal"
"github.com/jpicht/azcat/pkg/azcat"
)

func main() {
internal.Main(azcat.EMode.Read())
internal.Main(actions.EMode.Read())
}
4 changes: 2 additions & 2 deletions cmd/multi/azls/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"github.com/jpicht/azcat/actions"
"github.com/jpicht/azcat/internal"
"github.com/jpicht/azcat/pkg/azcat"
)

func main() {
internal.Main(azcat.EMode.List())
internal.Main(actions.EMode.List())
}
4 changes: 2 additions & 2 deletions cmd/multi/azput/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"github.com/jpicht/azcat/actions"
"github.com/jpicht/azcat/internal"
"github.com/jpicht/azcat/pkg/azcat"
)

func main() {
internal.Main(azcat.EMode.Write())
internal.Main(actions.EMode.Write())
}
4 changes: 2 additions & 2 deletions cmd/multi/azrm/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"github.com/jpicht/azcat/actions"
"github.com/jpicht/azcat/internal"
"github.com/jpicht/azcat/pkg/azcat"
)

func main() {
internal.Main(azcat.EMode.Remove())
internal.Main(actions.EMode.Remove())
}
2 changes: 1 addition & 1 deletion internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/url"

"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/jpicht/azcat/pkg/auth"
"github.com/jpicht/azcat/auth"
"github.com/sirupsen/logrus"
)

Expand Down
6 changes: 3 additions & 3 deletions internal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package internal

import (
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/jpicht/azcat/pkg/azcat"
"github.com/jpicht/azcat/actions"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
)

func Main(mode azcat.Mode) {
func Main(mode actions.Mode) {
pflag.Parse()

if *debug {
Expand All @@ -26,5 +26,5 @@ func Main(mode azcat.Mode) {

serviceClient := GetClient(parsed)

azcat.Run(mode, parsed, serviceClient)
actions.Run(mode, parsed, serviceClient)
}

0 comments on commit 7621ce6

Please sign in to comment.