Skip to content
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

Open
JustSteveKing opened this issue Oct 9, 2024 · 5 comments
Open

Spinner input #2

JustSteveKing opened this issue Oct 9, 2024 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@JustSteveKing
Copy link

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?

@orochaa
Copy link
Owner

orochaa commented Oct 9, 2024

Hey @JustSteveKing, thanks for filling this issue!

Could you please provide an snippet so I can reproduce it?

@JustSteveKing
Copy link
Author

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)
}

@JustSteveKing
Copy link
Author

Hey @Mist3rBru did you have any thoughts on this at all?

@orochaa
Copy link
Owner

orochaa commented Oct 16, 2024

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.

@JustSteveKing
Copy link
Author

Thanks for looking into it @Mist3rBru

@orochaa orochaa added the help wanted Extra attention is needed label Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants