-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spinner input #2
Comments
Hey @JustSteveKing, thanks for filling this issue! Could you please provide an snippet so I can reproduce it? |
Here it is @Mist3rBru package cmd
import (
"fmt"
"os"
"os/exec"
"github.com/Mist3rBru/go-clack/prompts"
"github.com/spf13/cobra"
)
var rebuildCmd = &cobra.Command{
Use: "rebuild",
Short: "Rebuild nix config for mac.",
Run: func(cmd *cobra.Command, args []string) {
prompts.Intro("Let's rebuild your nix configuration.")
homeDir, _ := os.UserHomeDir()
s := prompts.Spinner(prompts.SpinnerOptions{})
s.Start("Rebuilding nix config using flake 'main'")
command := exec.Command("darwin-rebuild", "switch", "--flake", homeDir+"/.config/nix#main")
command.Stdin = os.Stdin
command.Stdout = os.Stdout
command.Stderr = os.Stderr
if err := command.Run(); err != nil {
s.Stop(fmt.Sprintf("Something went wrong: %v", err), 1)
}
s.Stop("All good", 0)
prompts.Outro("Nix configuration rebuilt.")
},
}
func init() {
rootCmd.AddCommand(rebuildCmd)
} |
Hey @Mist3rBru did you have any thoughts on this at all? |
I looked into it, and it seems the OS treats the request for permission and the command execution as a single process, so we can't separate them in this way. Some possible workarounds would be to request permission to switch to the root (sudo) user, then run a spinner while the command is executed, but this isn't a good user experience. Or just run it without the spinner. Otherwise, I don't see a viable solution. I would consider this a known limitation and suggest keeping the issue open. |
Thanks for looking into it @Mist3rBru |
I am using the spinner atm to run a shell command, and it seems to hang. I know that the command asks for my root password to run - is there something I need to do to allow the spinner to do this?
The text was updated successfully, but these errors were encountered: