intake/cmd/root.go

45 lines
824 B
Go

package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "intake",
Short: "Universal and extensible feed aggregator",
Long: `intake, the universal and extensible feed aggregator`,
}
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
var dbPath string
func init() {
// Disable the automatic help command
rootCmd.SetHelpCommand(&cobra.Command{Hidden: true})
// All commands need to operate on a database
rootCmd.PersistentFlags().StringVarP(&dbPath, "db", "d", "", "Path to the intake sqlite database")
}
func getDbPath() string {
if dbPath != "" {
return dbPath
}
env := os.Getenv("INTAKE_DB")
if env != "" {
return env
}
fmt.Println("error: No database specified. Either --db or INTAKE_DB must be set.")
os.Exit(1)
return ""
}