add force flag to delete user command
This commit is contained in:
parent
87f93db6a4
commit
bc6b572eed
2 changed files with 16 additions and 9 deletions
|
@ -44,9 +44,12 @@ Commands:
|
||||||
create --user=USER --password=PASSWORD
|
create --user=USER --password=PASSWORD
|
||||||
Create user.
|
Create user.
|
||||||
|
|
||||||
delete --user=USER
|
delete --user=USER [<flags>]
|
||||||
Delete user.
|
Delete user.
|
||||||
|
|
||||||
|
flags:
|
||||||
|
--force Delete from db
|
||||||
|
|
||||||
revoke --user=USER
|
revoke --user=USER
|
||||||
Revoke user.
|
Revoke user.
|
||||||
|
|
||||||
|
@ -63,5 +66,5 @@ Commands:
|
||||||
Auth user.
|
Auth user.
|
||||||
|
|
||||||
change-password --user=USER --password=PASSWORD
|
change-password --user=USER --password=PASSWORD
|
||||||
Change password
|
Change password.
|
||||||
```
|
```
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
version = "1.0.3"
|
version = "1.0.4"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -25,6 +25,7 @@ var (
|
||||||
createCommandPasswordFlag = createCommand.Flag("password", "Password.").Required().String()
|
createCommandPasswordFlag = createCommand.Flag("password", "Password.").Required().String()
|
||||||
|
|
||||||
deleteCommand = kingpin.Command("delete", "Delete user.")
|
deleteCommand = kingpin.Command("delete", "Delete user.")
|
||||||
|
deleteCommandUserForceFlag = deleteCommand.Flag("force", "delete from db.").Default("false").Bool()
|
||||||
deleteCommandUserFlag = deleteCommand.Flag("user", "Username.").Required().String()
|
deleteCommandUserFlag = deleteCommand.Flag("user", "Username.").Required().String()
|
||||||
|
|
||||||
revokeCommand = kingpin.Command("revoke", "Revoke user.")
|
revokeCommand = kingpin.Command("revoke", "Revoke user.")
|
||||||
|
@ -48,7 +49,6 @@ var (
|
||||||
changePasswordCommandPasswordFlag = changePasswordCommand.Flag("password", "Password.").Required().String()
|
changePasswordCommandPasswordFlag = changePasswordCommand.Flag("password", "Password.").Required().String()
|
||||||
|
|
||||||
debug = kingpin.Flag("debug", "Enable debug mode.").Default("false").Bool()
|
debug = kingpin.Flag("debug", "Enable debug mode.").Default("false").Bool()
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
|
@ -119,7 +119,11 @@ func createUser(username, password string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteUser(username string) {
|
func deleteUser(username string) {
|
||||||
res, err := getDb().Exec("UPDATE users SET deleted = 1 WHERE username = $1", username)
|
deleteQuery := "UPDATE users SET deleted = 1 WHERE username = $1"
|
||||||
|
if *deleteCommandUserForceFlag {
|
||||||
|
deleteQuery = "DELETE FROM users WHERE username = $1"
|
||||||
|
}
|
||||||
|
res, err := getDb().Exec(deleteQuery, username)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
if rowsAffected, rowsErr := res.RowsAffected(); rowsErr != nil {
|
if rowsAffected, rowsErr := res.RowsAffected(); rowsErr != nil {
|
||||||
if rowsAffected == 1 {
|
if rowsAffected == 1 {
|
||||||
|
|
Loading…
Reference in a new issue