From 8b6012034227a50a9b84f788997575aa5d8213d0 Mon Sep 17 00:00:00 2001 From: rwxd Date: Tue, 10 Oct 2023 21:23:17 +0200 Subject: [PATCH] fix(cmd unlock): add force flag --- cmd/unlock.go | 5 ++++- docs/pages/cli/unlock.md | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/unlock.go b/cmd/unlock.go index 042d43a..cc109ae 100644 --- a/cmd/unlock.go +++ b/cmd/unlock.go @@ -20,7 +20,9 @@ To check you can run "ps aux | grep autorestic".`, Run: func(cmd *cobra.Command, args []string) { internal.GetConfig() - if isAutoresticRunning() { + force, _ := cmd.Flags().GetBool("force") + + if !force && isAutoresticRunning() { colors.Error.Print("Another autorestic instance is running. Are you sure you want to unlock? (yes/no): ") var response string fmt.Scanln(&response) @@ -42,6 +44,7 @@ To check you can run "ps aux | grep autorestic".`, func init() { rootCmd.AddCommand(unlockCmd) + unlockCmd.Flags().Bool("force", false, "force unlock") } // isAutoresticRunning checks if autorestic is running diff --git a/docs/pages/cli/unlock.md b/docs/pages/cli/unlock.md index 96096f5..cb507c6 100644 --- a/docs/pages/cli/unlock.md +++ b/docs/pages/cli/unlock.md @@ -24,3 +24,9 @@ root 39260 0.0 0.0 6976 2696 pts/11 S+ 19:41 0:00 grep autorest ```bash autorestic unlock ``` + +Use the `--force` to prevent the confirmation prompt if an instance is running. + +```bash +autorestic unlock --force +```