Skip to content

Commit

Permalink
Added 'repo alias' command
Browse files Browse the repository at this point in the history
With the repo alias command you can declare shorthands for your repository
configurations.
  • Loading branch information
penguwin committed May 31, 2020
1 parent acd407e commit 3308474
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion cmd/knoxite/repository.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* knoxite
* Copyright (c) 2016-2020, Christian Muehlhaeuser <muesli@gmail.com>
* Copyright (c) 2020, Nicolas Martin <penguwin@penguwin.eu>
*
* For license see LICENSE
*/
Expand All @@ -16,10 +17,10 @@ import (
"github.com/spf13/cobra"

"github.com/knoxite/knoxite"
"github.com/knoxite/knoxite/cfg"
"github.com/knoxite/knoxite/utils"
)

// Error declarations
var (
repoCmd = &cobra.Command{
Use: "repo",
Expand Down Expand Up @@ -78,6 +79,17 @@ var (
return executeRepoPack()
},
}
repoAliasCmd = &cobra.Command{
Use: "alias <alias>",
Short: "Set an alias for the storage backend url to a repository",
Long: `The set command adds an alias for the storage backend url to a repository`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return fmt.Errorf("alias needs an ALIAS to set")
}
return executeRepoAlias(args[0])
},
}
)

func init() {
Expand All @@ -87,6 +99,7 @@ func init() {
repoCmd.AddCommand(repoInfoCmd)
repoCmd.AddCommand(repoAddCmd)
repoCmd.AddCommand(repoPackCmd)
repoCmd.AddCommand(repoAliasCmd)
RootCmd.AddCommand(repoCmd)
}

Expand Down Expand Up @@ -198,6 +211,18 @@ func executeRepoPack() error {
return nil
}

func executeRepoAlias(alias string) error {
// At first check if the configuration file already exists
config.Repositories[alias] = cfg.RepoConfig{
Url: globalOpts.Repo,
// Compression: utils.CompressionText(knoxite.CompressionNone),
// Tolerance: 0,
// Encryption: utils.EncryptionText(knoxite.EncryptionAES),
}

return config.Save()
}

func executeRepoInfo() error {
r, err := openRepository(globalOpts.Repo, globalOpts.Password)
if err != nil {
Expand Down

0 comments on commit 3308474

Please sign in to comment.