2018-07-14 13:49:16 -04:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
2018-07-14 22:46:24 -04:00
|
|
|
"github.com/spf13/viper"
|
2018-07-15 23:53:33 -04:00
|
|
|
|
|
|
|
"git.metaunix.net/metaunix.net/muldap/cmd/group"
|
2018-08-27 16:29:36 -04:00
|
|
|
"git.metaunix.net/metaunix.net/muldap/cmd/ldif"
|
2018-07-20 14:21:51 -04:00
|
|
|
"git.metaunix.net/metaunix.net/muldap/cmd/user"
|
2023-03-29 18:07:46 -04:00
|
|
|
"git.metaunix.net/metaunix.net/muldap/cmd/web"
|
2018-07-14 16:03:54 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
// define global CLI flags
|
2018-07-14 22:46:24 -04:00
|
|
|
rootCmd.PersistentFlags().StringP("host", "H", "ldap.example.com", "LDAP host to perform operations on")
|
|
|
|
rootCmd.PersistentFlags().IntP("port", "p", 389, "TCP port that the LDAP host is listening on")
|
|
|
|
// bind config file values to flags
|
|
|
|
viper.BindPFlag("host", rootCmd.PersistentFlags().Lookup("host"))
|
|
|
|
viper.BindPFlag("port", rootCmd.PersistentFlags().Lookup("port"))
|
2018-07-15 23:53:33 -04:00
|
|
|
|
|
|
|
// register commands
|
2023-03-29 18:07:46 -04:00
|
|
|
rootCmd.AddCommand(group.GroupCmd, ldif.LdifCmd, user.UserCmd, web.WebCmd, searchCmd, setupCmd, versionCmd)
|
2018-07-14 16:03:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// define root command
|
2018-07-14 13:49:16 -04:00
|
|
|
var rootCmd = &cobra.Command{
|
|
|
|
Use: "muldap",
|
|
|
|
Short: "muldap is Metaunix.net's LDAP management tool",
|
|
|
|
Long: "LDAP management tool for Metaunix.net user and group resources.",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2018-07-20 14:21:51 -04:00
|
|
|
fmt.Println("Metaunix.net LDAP tool - available commands are: group, user, search, setup, version")
|
2018-07-14 13:49:16 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-07-14 16:03:54 -04:00
|
|
|
// start CLI app
|
2018-07-14 13:49:16 -04:00
|
|
|
func Execute() {
|
|
|
|
if err := rootCmd.Execute(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|