-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add list roles command - add roles associated with users in list users
- Loading branch information
1 parent
4239225
commit 4cd8816
Showing
4 changed files
with
91 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/hiperdk/pg_user/database" | ||
"github.com/olekukonko/tablewriter" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
var rolesCmd = &cobra.Command{ | ||
Use: "roles [host]", | ||
Short: "List database roles", | ||
Long: `List database roles for a specific database`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) != 1 { | ||
cmd.Println(cmd.UsageString()) | ||
os.Exit(1) | ||
} | ||
|
||
host := args[0] | ||
|
||
conn := database.GetDatabaseEntryConnection(host) | ||
if conn == nil { | ||
cmd.Println("no hosts found by that name") | ||
os.Exit(1) | ||
} | ||
|
||
listRolesForConnection(conn) | ||
}, | ||
} | ||
|
||
func listRolesForConnection(conn *database.DBConn) { | ||
roles, err := conn.GetAllRoles() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
table := tablewriter.NewWriter(os.Stdout) | ||
table.SetHeader([]string{"rolename"}) | ||
|
||
for _, r := range roles { | ||
table.Append([]string{ | ||
r, | ||
}) | ||
} | ||
|
||
table.Render() | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(rolesCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters