Skip to content

Commit

Permalink
Rename the 'cfg' package to 'config'
Browse files Browse the repository at this point in the history
  • Loading branch information
penguwin committed Aug 4, 2020
1 parent 1eec766 commit 4917e1d
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 28 deletions.
20 changes: 10 additions & 10 deletions cmd/knoxite/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strconv"
"strings"

"github.com/knoxite/knoxite/cfg"
"github.com/knoxite/knoxite/config"
"github.com/muesli/gotable"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -85,20 +85,20 @@ func init() {
}

func executeConfigInit() error {
log.Printf("Writing configuration file to: %s\n", config.URL().Path)
return config.Save()
log.Printf("Writing configuration file to: %s\n", cfg.URL().Path)
return cfg.Save()
}

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

return config.Save()
return cfg.Save()
}

func executeConfigSet(option string, value string) error {
Expand All @@ -110,7 +110,7 @@ func executeConfigSet(option string, value string) error {
}

// The first part should be the repos alias
repo, ok := config.Repositories[strings.ToLower(parts[0])]
repo, ok := cfg.Repositories[strings.ToLower(parts[0])]
if !ok {
return fmt.Errorf("No alias with name %s found", parts[0])
}
Expand All @@ -132,9 +132,9 @@ func executeConfigSet(option string, value string) error {
default:
return fmt.Errorf("Unknown configuration option: %s", opt)
}
config.Repositories[strings.ToLower(parts[0])] = repo
cfg.Repositories[strings.ToLower(parts[0])] = repo

return config.Save()
return cfg.Save()
}

func executeConfigInfo() error {
Expand All @@ -143,7 +143,7 @@ func executeConfigInfo() error {
[]int64{-15, -35, -15, -15, 15},
"No repository configurations found.")

for alias, repo := range config.Repositories {
for alias, repo := range cfg.Repositories {
tab.AppendRow([]interface{}{
alias,
repo.Url,
Expand All @@ -156,7 +156,7 @@ func executeConfigInfo() error {
}

func executeConfigCat() error {
json, err := json.MarshalIndent(config, "", " ")
json, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
return err
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/knoxite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
shutdown "github.com/klauspost/shutdown2"
"github.com/spf13/cobra"

"github.com/knoxite/knoxite/cfg"
"github.com/knoxite/knoxite/config"
_ "github.com/knoxite/knoxite/storage/azure"
_ "github.com/knoxite/knoxite/storage/backblaze"
_ "github.com/knoxite/knoxite/storage/dropbox"
Expand All @@ -43,7 +43,7 @@ var (
CommitSHA = ""

globalOpts = GlobalOptions{}
config = &cfg.Config{}
cfg = &config.Config{}

// RootCmd is the core command used for cli-arg parsing
RootCmd = &cobra.Command{
Expand All @@ -64,7 +64,7 @@ func main() {

RootCmd.PersistentFlags().StringVarP(&globalOpts.Repo, "repo", "r", "", "Repository directory to backup to/restore from (default: current working dir)")
RootCmd.PersistentFlags().StringVarP(&globalOpts.Password, "password", "p", "", "Password to use for data encryption")
RootCmd.PersistentFlags().StringVarP(&globalOpts.ConfigURL, "configURL", "C", cfg.DefaultPath(), "Path to the configuration file")
RootCmd.PersistentFlags().StringVarP(&globalOpts.ConfigURL, "configURL", "C", config.DefaultPath(), "Path to the configuration file")

globalOpts.Repo = os.Getenv("KNOXITE_REPOSITORY")
globalOpts.Password = os.Getenv("KNOXITE_PASSWORD")
Expand Down Expand Up @@ -93,20 +93,20 @@ func init() {
// ConfigURL flag.
func initConfig() {
var err error
config, err = cfg.New(globalOpts.ConfigURL)
cfg, err = config.New(globalOpts.ConfigURL)
if err != nil {
log.Fatalf("error reading the config file: %v\n", err)
return
}
if err = config.Load(); err != nil {
if err = cfg.Load(); err != nil {
log.Fatalf("error loading the config file: %v\n", err)
return
}

// There can occur a panic due to an entry assigment in nil map when theres
// no map initialized to store the RepoConfigs. This will prevent this from
// happening:
if config.Repositories == nil {
config.Repositories = make(map[string]cfg.RepoConfig)
if cfg.Repositories == nil {
cfg.Repositories = make(map[string]config.RepoConfig)
}
}
2 changes: 1 addition & 1 deletion cmd/knoxite/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func openRepository(path, password string) (knoxite.Repository, error) {
}
}

if rep, ok := config.Repositories[path]; ok {
if rep, ok := cfg.Repositories[path]; ok {
return knoxite.OpenRepository(rep.Url, password)
}
return knoxite.OpenRepository(path, password)
Expand Down
2 changes: 1 addition & 1 deletion cmd/knoxite/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var (
// When there exists a config for the repo we'll use the values from
// there unless the user sets another value via the command line flags.
func configureStoreOpts(cmd *cobra.Command, opts StoreOptions) StoreOptions {
if rep, ok := config.Repositories[globalOpts.Repo]; ok {
if rep, ok := cfg.Repositories[globalOpts.Repo]; ok {
if !cmd.Flags().Changed("compression") {
opts.Compression = rep.Compression
}
Expand Down
2 changes: 1 addition & 1 deletion cfg/aesbackend.go → config/aesbackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* For license see LICENSE
*/
package cfg
package config

import (
"crypto/aes"
Expand Down
2 changes: 1 addition & 1 deletion cfg/aesbackend_test.go → config/aesbackend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* For license see LICENSE
*/
package cfg
package config

import (
"io/ioutil"
Expand Down
2 changes: 1 addition & 1 deletion cfg/config.go → config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* For license see LICENSE
*/
package cfg
package config

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion cfg/config_test.go → config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* For license see LICENSE
*/
package cfg
package config

import (
"net/url"
Expand Down
3 changes: 1 addition & 2 deletions cfg/filebackend.go → config/filebackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
*
* For license see LICENSE
*/

package cfg
package config

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion cfg/filebackend_test.go → config/filebackend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* For license see LICENSE
*/
package cfg
package config

import (
"io/ioutil"
Expand Down
2 changes: 1 addition & 1 deletion cfg/membackend.go → config/membackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* For license see LICENSE
*/
package cfg
package config

import "net/url"

Expand Down
2 changes: 1 addition & 1 deletion cfg/membackend_test.go → config/membackend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* For license see LICENSE
*/
package cfg
package config

import (
"net/url"
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 4917e1d

Please sign in to comment.