cmd

package
v0.2.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2026 License: LGPL-2.1 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "rrb",
	Short: "A filesystem watcher that runs commands on changes",
	Long: "This command watches the filesystem and waits for file changes. When it " +
		"happens, it invokes the given command. If a command was already being previously " +
		"executed, then its process tree is gracefully terminated, before running the " +
		"command again.",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			logrus.Fatal("Missing build command.")
			os.Exit(1)
		}

		w, err := watcher.NewWatcher(watcher.Config{
			RootPath:         directory,
			Patterns:         patterns,
			IgnorePatterns:   ignorePatterns,
			DebounceDuration: debounce,
		})
		if err != nil {
			logrus.Fatalf("NewWatcher: %s", err.Error())
		}
		defer w.Close()

		r := runner.NewRunner(killWait, args[0], args[1:]...)

		sigCn := make(chan os.Signal, 1)
		signal.Notify(sigCn, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)

		for {
			select {
			case <-w.ChangedFilesCn:
				if err := r.Run(); err != nil {
					logrus.Fatal(err)
				}
			case err := <-w.ErrorsCn:
				logrus.Fatal(err)
			case sig := <-sigCn:
				logrus.Warnf("Signal %s received!", sig)
				r.Kill()
				logrus.Fatal("Exiting")
			}
		}
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL