config

package
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package db /*

Index

Constants

This section is empty.

Variables

View Source
var ConfigCmd = &cobra.Command{
	Use:   "config",
	Short: "Show the current Pennsieve configuration file.",
	Long:  `Show the current Pennsieve configuration file.`,
	Run: func(cmd *cobra.Command, args []string) {

		home, err := os.UserHomeDir()
		pennsieveFolder := filepath.Join(home, ".pennsieve")
		configFile := filepath.Join(pennsieveFolder, "config.ini")
		data, err := ioutil.ReadFile(configFile)
		if err != nil {
			fmt.Println("Unable to render Pennsieve configuration file.")
			os.Exit(1)
		}
		fmt.Println(string(data))

	},
}
View Source
var WizardCmd = &cobra.Command{
	Use:   "wizard",
	Short: "Create a new config file using the configuration wizard.",
	Long: `Create a new config file using the configuration wizard.



`,
	Run: func(cmd *cobra.Command, args []string) {

		home, err := os.UserHomeDir()
		pennsieveFolder := filepath.Join(home, ".pennsieve")
		configFile := filepath.Join(pennsieveFolder, "config.ini")

		_, err = os.Stat(configFile)
		if err == nil {
			fmt.Println("Existing configuration file found at:", configFile)
			fmt.Printf("\nWould you like to overwrite your existing configuration? (y/n): ")

			response := ""
			fmt.Scanln(&response)

			if response != "y" {
				return
			}

			os.Remove(configFile)
		}

		fmt.Println("\nCreating new configuration file at", configFile)

		if _, err := os.Stat(pennsieveFolder); errors.Is(err, os.ErrNotExist) {
			if err := os.Mkdir(pennsieveFolder, os.ModePerm); err != nil {
				log.Fatal(err)
			}
		}

		var profileName string
		fmt.Println("\nCreate new profile:")
		fmt.Printf("   Profile name [user]: ")
		fmt.Scanln(&profileName)

		if len(profileName) == 0 {
			profileName = "user"
		}

		var apiToken string
		fmt.Printf("   API token: ")
		fmt.Scanln(&apiToken)

		var apiSecret string
		fmt.Printf("   API secret: ")
		fmt.Scanln(&apiSecret)

		fmt.Printf("Creating new profile: '%s'\n", profileName)

		fmt.Printf("Continue and write changes? (y/n) ")
		response := ""
		fmt.Scanln(&response)

		if response == "y" {
			viper.Set(fmt.Sprintf("%s.api_token", profileName), apiToken)
			viper.Set(fmt.Sprintf("%s.api_secret", profileName), apiSecret)
			viper.Set("global.default_profile", profileName)

			err = viper.SafeWriteConfig()
			if err != nil {
				fmt.Println(err)
			}
		}
	},
}

Functions

func InitDB added in v1.0.0

func InitDB()

InitDB is used in every (except config) CMD to initialize configuration and DB.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL