layerform icon indicating copy to clipboard operation
layerform copied to clipboard

Add a `--auto-approve` flag to `layerform kill`

Open vieiralucas opened this issue 1 year ago • 4 comments

Problem:

When using layerform in a script, or CI environment, I want to be able to kill layer instances without having to answer yes to the "are you sure?" question.

Proposal:

Add a --auto-approve flag to the kill command that makes the cli skip the confirmation when killing a layer instance.

vieiralucas avatar Sep 07 '23 20:09 vieiralucas

This should be an easy one, first thing is to add the flag here: https://github.com/ergomake/layerform/blob/a4a1cefa32b826efd07900e1b05a9f03c7a3f55f/cmd/cli/kill.go#L17-L21 Something like this

  killCmd.Flags().Bool("auto-approve", false, "skip interactive approval before killing layer instance")

Then, do an if statement over here: https://github.com/ergomake/layerform/blob/a4a1cefa32b826efd07900e1b05a9f03c7a3f55f/internal/command/kill.go#L185-L194 Something like this:

	if !autoApprove {
		var answer string
		fmt.Print("Are you sure? This can't be undone. [yes/no]: ")
		_, err = fmt.Scan(&answer)
		if err != nil {
			return errors.Wrap(err, "fail to read asnwer")
		}

		if strings.ToLower(strings.TrimSpace(answer)) != "yes" {
			return nil
		}
	}

Besides that, you'll need to pass some arguments around. I'm happy to further assist.

vieiralucas avatar Sep 07 '23 21:09 vieiralucas

Hi, is this issue still available to been worked on? Can i try to fixed with your suggestions? =]

hi-hi-ray avatar Sep 08 '23 01:09 hi-hi-ray

Hey @hi-hi-ray, yes please. Let me know if you want some help. I'll assign to you just to let other people know ok? Thank you in advance!

vieiralucas avatar Sep 08 '23 04:09 vieiralucas

Hi, I created the PR it worked here, but to ensure that everything it's ok I strongly advise that you test in your local environments. =]

hi-hi-ray avatar Sep 10 '23 20:09 hi-hi-ray