diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..7682d96 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +MFA_MINIFLUX_HOST=rss.miniflux.net +MFA_MINIFLUX_TOKEN=ASDF + +MFA_SERVICE_HOST=rss.linkding.net +MFA_SERVICE_USER=john.doe@mail.com +MFA_SERVICE_TOKEN=ASDF diff --git a/.gitignore b/.gitignore index c1c145d..9f84a6e 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ pip-selfcheck.json secring.* +.env diff --git a/.justfile b/.justfile index b334ac8..c8ecec6 100644 --- a/.justfile +++ b/.justfile @@ -1,2 +1,2 @@ run: - go run main.go + go run main.go run linkding diff --git a/cmd/archive.go b/cmd/archive.go new file mode 100644 index 0000000..9492ec0 --- /dev/null +++ b/cmd/archive.go @@ -0,0 +1,46 @@ +/* +Copyright © 2024 NAME HERE +*/ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +var Services = []string{ + "linkding", +} + +var ( + service_host string + service_user string + service_token string +) + +// archiveCmd represents the archive command +var archiveCmd = &cobra.Command{ + Use: "archive", + Short: "Archive the rss entries to an external service.", + Aliases: []string{"run"}, + Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), + ValidArgs: Services, + Run: func(cmd *cobra.Command, args []string) { + // service := args[0] + fmt.Printf("%v", viper.AllSettings()) + }, +} + +func init() { + rootCmd.AddCommand(archiveCmd) + + archiveCmd.Flags().StringVar(&service_host, "service-host", "", "127.0.0.1") + archiveCmd.Flags().StringVar(&service_user, "service-user", "", "john.doe@mail.cl") + archiveCmd.Flags().StringVar(&service_token, "service-token", "", "XXX-XXX-XXX") + + viper.BindPFlag("service_host", archiveCmd.Flags().Lookup("service-host")) + viper.BindPFlag("service_host", archiveCmd.Flags().Lookup("service-host")) + viper.BindPFlag("service_token", archiveCmd.Flags().Lookup("service-token")) +} diff --git a/cmd/root.go b/cmd/root.go index 6a187b7..02f96ad 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -7,6 +7,7 @@ import ( "fmt" "os" + "github.com/joho/godotenv" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -37,6 +38,8 @@ func Execute() { } func init() { + godotenv.Load() + cobra.OnInitialize(initConfig) // Here you will define your flags and configuration settings. @@ -75,4 +78,19 @@ func initConfig() { if err := viper.ReadInConfig(); err == nil { fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed()) } + + requiredParams := [...]string{ + "miniflux_host", + "miniflux_token", + } + + for _, param := range requiredParams { + if !viper.IsSet(param) { + fmt.Printf( + "Error: The value \"%v\" must be set. For more information use the --help command\n", + param, + ) + os.Exit(1) + } + } } diff --git a/go.mod b/go.mod index 14ade84..7a7f991 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module git.alecodes.page/alecodes/miniflux-archiver go 1.23.3 require ( + github.com/joho/godotenv v1.5.1 github.com/spf13/cobra v1.8.1 github.com/spf13/viper v1.19.0 ) diff --git a/go.sum b/go.sum index aba9163..c17479d 100644 --- a/go.sum +++ b/go.sum @@ -13,6 +13,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= diff --git a/main.go b/main.go index cfb82e1..efbc1cf 100644 --- a/main.go +++ b/main.go @@ -1,10 +1,11 @@ /* Copyright © 2024 NAME HERE - */ package main -import "git.alecodes.page/alecodes/miniflux-archiver/cmd" +import ( + "git.alecodes.page/alecodes/miniflux-archiver/cmd" +) func main() { cmd.Execute()