Added some global flags to specify LDAP host and port to connect to
This commit is contained in:
parent
5d2a7f4304
commit
9e59f510a1
13
cmd/root.go
13
cmd/root.go
@ -7,6 +7,18 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
flagHost string
|
||||
flagPort int
|
||||
)
|
||||
|
||||
func init() {
|
||||
// define global CLI flags
|
||||
rootCmd.PersistentFlags().StringVarP(&flagHost, "host", "H", "ldap.example.com", "LDAP host to perform operations on")
|
||||
rootCmd.PersistentFlags().IntVarP(&flagPort, "port", "p", 389, "TCP port that the LDAP host is listening on")
|
||||
}
|
||||
|
||||
// define root command
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "muldap",
|
||||
Short: "muldap is Metaunix.net's LDAP management tool",
|
||||
@ -16,6 +28,7 @@ var rootCmd = &cobra.Command{
|
||||
},
|
||||
}
|
||||
|
||||
// start CLI app
|
||||
func Execute() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
|
@ -31,7 +31,7 @@ var searchCmd = &cobra.Command{
|
||||
Long: `Perform an LDAP search operation on an LDAP directory`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// create new LDAP connection
|
||||
l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", "ldap.example.com", 389))
|
||||
l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", flagHost, flagPort))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user