-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in release/0.4.0 (pull request #4)
Merge release/0.4.0
- Loading branch information
Showing
43 changed files
with
1,222 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package artifact | ||
|
||
import ( | ||
"fmt" | ||
|
||
"bitbucket.org/gildas_cherruel/bb/cmd/link" | ||
"bitbucket.org/gildas_cherruel/bb/cmd/user" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type Artifact struct { | ||
Name string `json:"name" mapstructure:"name"` | ||
Size uint64 `json:"size" mapstructure:"size"` | ||
Downloads uint64 `json:"downloads" mapstructure:"downloads"` | ||
User user.User `json:"user" mapstructure:"user"` | ||
Links link.Links `json:"links" mapstructure:"links"` | ||
} | ||
|
||
var Command = &cobra.Command{ | ||
Use: "artifact", | ||
Short: "Manage artifacts", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("Artifact requires a subcommand:") | ||
for _, command := range cmd.Commands() { | ||
fmt.Println(command.Name()) | ||
} | ||
}, | ||
} | ||
|
||
// GetHeader gets the header for a table | ||
// | ||
// implements common.Tableable | ||
func (artifact Artifact) GetHeader(short bool) []string { | ||
return []string{"Name", "Size", "Downloads", "Owner"} | ||
} | ||
|
||
// GetRow gets the row for a table | ||
// | ||
// implements common.Tableable | ||
func (artifact Artifact) GetRow(headers []string) []string { | ||
return []string{ | ||
artifact.Name, | ||
fmt.Sprintf("%d", artifact.Size), | ||
fmt.Sprintf("%d", artifact.Downloads), | ||
artifact.User.Name, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package artifact | ||
|
||
type Artifacts []Artifact | ||
|
||
// GetHeader gets the headers for the list command | ||
// | ||
// implements common.Tableables | ||
func (artifacts Artifacts) GetHeader() []string { | ||
return Artifact{}.GetHeader(false) | ||
} | ||
|
||
// GetRowAt gets the row for the list command | ||
// | ||
// implements common.Tableables | ||
func (artifacts Artifacts) GetRowAt(index int) []string { | ||
if index < 0 || index >= len(artifacts) { | ||
return []string{} | ||
} | ||
return artifacts[index].GetRow(nil) | ||
} | ||
|
||
// Size gets the number of elements | ||
// | ||
// implements common.Tableables | ||
func (artifacts Artifacts) Size() int { | ||
return len(artifacts) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package artifact | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"bitbucket.org/gildas_cherruel/bb/cmd/profile" | ||
"github.com/gildas/go-errors" | ||
"github.com/gildas/go-logger" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var deleteCmd = &cobra.Command{ | ||
Use: "delete", | ||
Short: "delete an artifact by its filename", | ||
Args: cobra.ExactArgs(1), | ||
RunE: deleteProcess, | ||
} | ||
|
||
var deleteOptions struct { | ||
Repository string | ||
} | ||
|
||
func init() { | ||
Command.AddCommand(deleteCmd) | ||
|
||
deleteCmd.Flags().StringVar(&deleteOptions.Repository, "repository", "", "Repository to delete artifacts from. Defaults to the current repository") | ||
} | ||
|
||
func deleteProcess(cmd *cobra.Command, args []string) error { | ||
log := logger.Must(logger.FromContext(cmd.Context())).Child(cmd.Parent().Name(), "delete") | ||
|
||
if profile.Current == nil { | ||
return errors.ArgumentMissing.With("profile") | ||
} | ||
|
||
log.Infof("Deleting artifact %s from repository %s with profile %s", args[0], listOptions.Repository, profile.Current) | ||
err := profile.Current.Delete( | ||
log.ToContext(cmd.Context()), | ||
deleteOptions.Repository, | ||
fmt.Sprintf("downloads/%s", args[0]), | ||
nil, | ||
) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Failed to delete artifact %s: %s\n", args[0], err) | ||
os.Exit(1) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package artifact | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"bitbucket.org/gildas_cherruel/bb/cmd/profile" | ||
"github.com/gildas/go-errors" | ||
"github.com/gildas/go-logger" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var downloadCmd = &cobra.Command{ | ||
Use: "download", | ||
Aliases: []string{"get", "fetch"}, | ||
Short: "download an artifact", | ||
Args: cobra.ExactArgs(1), | ||
RunE: getProcess, | ||
} | ||
|
||
var downloadOptions struct { | ||
Repository string | ||
Destination string | ||
} | ||
|
||
func init() { | ||
Command.AddCommand(downloadCmd) | ||
|
||
downloadCmd.Flags().StringVar(&downloadOptions.Repository, "repository", "", "Repository to download artifacts from. Defaults to the current repository") | ||
downloadCmd.Flags().StringVar(&downloadOptions.Destination, "destination", "", "Destination folder to download the artifact to. Defaults to the current folder") | ||
_ = downloadCmd.MarkFlagDirname("destination") | ||
} | ||
|
||
func getProcess(cmd *cobra.Command, args []string) error { | ||
log := logger.Must(logger.FromContext(cmd.Context())).Child(cmd.Parent().Name(), "download") | ||
|
||
if profile.Current == nil { | ||
return errors.ArgumentMissing.With("profile") | ||
} | ||
|
||
log.Infof("Downloading artifact %s", args[0]) | ||
|
||
err := profile.Current.Download( | ||
log.ToContext(cmd.Context()), | ||
downloadOptions.Repository, | ||
fmt.Sprintf("downloads/%s", args[0]), | ||
downloadOptions.Destination, | ||
) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Failed to download artifact %s: %s\n", args[0], err) | ||
os.Exit(1) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package artifact | ||
|
||
import ( | ||
"bitbucket.org/gildas_cherruel/bb/cmd/profile" | ||
"github.com/gildas/go-errors" | ||
"github.com/gildas/go-logger" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var listCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "list all projects", | ||
Args: cobra.NoArgs, | ||
RunE: listProcess, | ||
} | ||
|
||
var listOptions struct { | ||
Repository string | ||
} | ||
|
||
func init() { | ||
Command.AddCommand(listCmd) | ||
|
||
listCmd.Flags().StringVar(&listOptions.Repository, "repository", "", "Repository to list artifacts from. Defaults to the current repository") | ||
} | ||
|
||
func listProcess(cmd *cobra.Command, args []string) (err error) { | ||
log := logger.Must(logger.FromContext(cmd.Context())).Child(cmd.Parent().Name(), "list") | ||
|
||
if profile.Current == nil { | ||
return errors.ArgumentMissing.With("profile") | ||
} | ||
|
||
log.Infof("Listing all projects from repository %s with profile %s", listOptions.Repository, profile.Current) | ||
artifacts, err := profile.GetAll[Artifact]( | ||
cmd.Context(), | ||
profile.Current, | ||
listOptions.Repository, | ||
"downloads", | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
if len(artifacts) == 0 { | ||
log.Infof("No artifact found") | ||
return nil | ||
} | ||
return profile.Current.Print(cmd.Context(), Artifacts(artifacts)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package artifact | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"bitbucket.org/gildas_cherruel/bb/cmd/profile" | ||
"github.com/gildas/go-errors" | ||
"github.com/gildas/go-logger" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var uploadCmd = &cobra.Command{ | ||
Use: "upload", | ||
Short: "upload an artifact", | ||
Args: cobra.ExactArgs(1), | ||
RunE: uploadProcess, | ||
} | ||
|
||
var uploadOptions struct { | ||
Repository string | ||
} | ||
|
||
func init() { | ||
Command.AddCommand(uploadCmd) | ||
|
||
uploadCmd.Flags().StringVar(&uploadOptions.Repository, "repository", "", "Repository to upload artifacts to. Defaults to the current repository") | ||
} | ||
|
||
func uploadProcess(cmd *cobra.Command, args []string) error { | ||
log := logger.Must(logger.FromContext(cmd.Context())).Child(cmd.Parent().Name(), "upload") | ||
|
||
if profile.Current == nil { | ||
return errors.ArgumentMissing.With("profile") | ||
} | ||
|
||
log.Infof("Uploading artifact %s", args[0]) | ||
|
||
err := profile.Current.Upload( | ||
log.ToContext(cmd.Context()), | ||
uploadOptions.Repository, | ||
"downloads", | ||
args[0], | ||
) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Failed to upload artifact %s: %s\n", args[0], err) | ||
os.Exit(1) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.