Compare commits

...

4 Commits

Author SHA1 Message Date
Neeraj Gupta
427968a1cd [cli][setup] add: public-albums-url subcommand to configure albums url (#4235)
Adds a command `ente setup public-albums-url`. 


![Capture-Nov-28-17-12-36](https://github.com/user-attachments/assets/1884332f-635e-4173-a48e-69d762725590)
2024-11-29 14:05:04 +05:30
mngshm
8b71ae3b33 chore: grouping imports 2024-11-29 13:45:31 +05:30
mngshm
185a013cff [ente-cli]fix: trim trailing slashes in albumsUrl 2024-11-29 13:41:11 +05:30
mngshm
5596f46047 [ente-cli]add: public-albums-url subcommand to configure albums url in config file via ente-cli 2024-11-28 17:10:06 +05:30
2 changed files with 86 additions and 0 deletions

72
cli/cmd/setup.go Normal file
View File

@@ -0,0 +1,72 @@
package cmd
import (
"fmt"
"os"
"net/url"
"strings"
"github.com/spf13/viper"
"github.com/spf13/cobra"
"github.com/ente-io/cli/pkg"
)
var setupCmd = &cobra.Command {
Use: "setup",
Short: "Manage setup/configuration settings",
}
// Command to set the public albums url in configurations/<environment>.yaml file
// Reads value from environment variable "ENTE_MUSEUM_DIR"
var addPublicAlbumsUrl = &cobra.Command {
Use: "public-albums-url account add-public-url [url]",
Short: "Set the public-albums URL in Museum YAML configuraiton file",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
// Get environment to make changes to valid file
environment := os.Getenv("ENVIRONMENT")
if environment == "" {
environment = "local"
}
dir := pkg.ConfigureServerDir()
// Adding path to the museum config file
viper.AddConfigPath(dir)
viper.SetConfigName(environment)
viper.SetConfigType("yaml")
err := viper.ReadInConfig()
if err != nil {
fmt.Errorf("%v", err)
return
}
albumsUrl := strings.TrimSuffix(args[0], "/")
_, err = url.ParseRequestURI(albumsUrl)
if err != nil {
// Report Error and exit
fmt.Printf("Invalid URL: %s\nPlease enter a valid endpoint for public albums", err)
os.Exit(1)
} else {
viper.Set("apps.public-albums", albumsUrl)
}
// Overwrite the public album url in Configuration File
err = viper.WriteConfig()
if err != nil {
fmt.Println("Error saving config: %v\n", err)
} else {
fmt.Println("Public Albums URL set to", albumsUrl)
}
},
}
func init() {
// `ente setup` will be the initial root command
rootCmd.AddCommand(setupCmd)
rootCmd.Flags().String("public-albums-url", "", "Sets the public-albums url in your environments configuration file")
setupCmd.AddCommand(addPublicAlbumsUrl)
}

View File

@@ -41,3 +41,17 @@ func GetCLITempPath() (string) {
}
return os.TempDir()
}
// Configure Museum Server Directory to find proper <environment.yaml> file.
// Made for and used in command `ente account public-albums-url [url]`
func ConfigureServerDir() (string) {
serverEnv := os.Getenv("ENTE_SERVER_DIR")
if serverEnv != "" {
fmt.Errorf(`ENTE_SERVER_DIR environment is not set, please setup it with\n
export ENTE_SERVER_DIR=/path/to/ente/
`)
}
configDir := filepath.Join(serverEnv, "server", "configurations")
return configDir
}