Add confirmation prompt to source deactivation
This commit is contained in:
parent
3d09e60e66
commit
5213045a33
@ -3,6 +3,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/Jaculabilis/intake/core"
|
"github.com/Jaculabilis/intake/core"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
@ -17,7 +18,7 @@ var deactivateCmd = &cobra.Command{
|
|||||||
|
|
||||||
Deactivation is idempotent.`,
|
Deactivation is idempotent.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
deactivate(stringArg(cmd, "source"), stringArg(cmd, "item"))
|
deactivate(stringArg(cmd, "source"), stringArg(cmd, "item"), boolArg(cmd, "yes"))
|
||||||
},
|
},
|
||||||
DisableFlagsInUseLine: true,
|
DisableFlagsInUseLine: true,
|
||||||
}
|
}
|
||||||
@ -28,21 +29,37 @@ func init() {
|
|||||||
deactivateCmd.Flags().StringP("source", "s", "", "Source of the item")
|
deactivateCmd.Flags().StringP("source", "s", "", "Source of the item")
|
||||||
deactivateCmd.MarkFlagRequired("source")
|
deactivateCmd.MarkFlagRequired("source")
|
||||||
deactivateCmd.Flags().StringP("item", "i", "", "Item id")
|
deactivateCmd.Flags().StringP("item", "i", "", "Item id")
|
||||||
|
deactivateCmd.Flags().BoolP("yes", "y", false, "Do not ask for confirmation")
|
||||||
}
|
}
|
||||||
|
|
||||||
func deactivate(source string, item string) {
|
func deactivate(source string, item string, yes bool) {
|
||||||
if source == "" {
|
if source == "" {
|
||||||
log.Fatal("error: --source is empty")
|
log.Fatal("error: --source is empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
db := openAndMigrateDb()
|
db := openAndMigrateDb()
|
||||||
|
|
||||||
|
exists, err := core.SourceExists(db, source)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("error: failed to check for source: %v", err)
|
||||||
|
} else if !exists {
|
||||||
|
log.Fatalf("error: no such source %s", source)
|
||||||
|
}
|
||||||
|
|
||||||
if item == "" {
|
if item == "" {
|
||||||
|
if !yes {
|
||||||
|
var response string
|
||||||
|
fmt.Printf("Are you sure you want to deactivate all items in source %s? (y/N): ", source)
|
||||||
|
_, err := fmt.Scanln(&response)
|
||||||
|
if err != nil || (response != "y" && response != "Y") {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
log.Fatal("source deactivation is not implemented")
|
log.Fatal("source deactivation is not implemented")
|
||||||
} else {
|
} else {
|
||||||
active, err := core.DeactivateItem(db, source, item)
|
active, err := core.DeactivateItem(db, source, item)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to deactivate item: %s", err)
|
log.Fatalf("error: failed to deactivate item: %s", err)
|
||||||
}
|
}
|
||||||
if active {
|
if active {
|
||||||
fmt.Printf("Deactivated %s/%s\n", source, item)
|
fmt.Printf("Deactivated %s/%s\n", source, item)
|
||||||
|
Loading…
Reference in New Issue
Block a user