fix(cmd unlock): add force flag

This commit is contained in:
rwxd 2023-10-10 21:23:17 +02:00
parent ba51d1d062
commit 8b60120342
No known key found for this signature in database
GPG Key ID: 8C3FE917649EDF11
2 changed files with 10 additions and 1 deletions

View File

@ -20,7 +20,9 @@ To check you can run "ps aux | grep autorestic".`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
internal.GetConfig() 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): ") colors.Error.Print("Another autorestic instance is running. Are you sure you want to unlock? (yes/no): ")
var response string var response string
fmt.Scanln(&response) fmt.Scanln(&response)
@ -42,6 +44,7 @@ To check you can run "ps aux | grep autorestic".`,
func init() { func init() {
rootCmd.AddCommand(unlockCmd) rootCmd.AddCommand(unlockCmd)
unlockCmd.Flags().Bool("force", false, "force unlock")
} }
// isAutoresticRunning checks if autorestic is running // isAutoresticRunning checks if autorestic is running

View File

@ -24,3 +24,9 @@ root 39260 0.0 0.0 6976 2696 pts/11 S+ 19:41 0:00 grep autorest
```bash ```bash
autorestic unlock autorestic unlock
``` ```
Use the `--force` to prevent the confirmation prompt if an instance is running.
```bash
autorestic unlock --force
```