Ejemplo n.º 1
0
Archivo: ifx.go Proyecto: tv42/redux
func redoIfX(args []string, fn func(*redux.File, *redux.File) error) error {

	dependentPath := os.Getenv("REDO_PARENT")
	if len(dependentPath) == 0 {
		return fmt.Errorf("Missing env variable REDO_PARENT")
	}

	wd := os.Getenv("REDO_PARENT_DIR")

	// The action is triggered by dependent.
	dependent, err := redux.NewFile(wd, dependentPath)
	if err != nil {
		return err
	}

	for _, path := range args {
		if file, err := redux.NewFile(wd, path); err != nil {
			return err
		} else if err := fn(file, dependent); err != nil {
			return err
		}
	}

	return nil
}
Ejemplo n.º 2
0
Archivo: redo.go Proyecto: tv42/redux
func runRedo(targets []string) error {

	// set options from environment if not provided.
	if verbosity.NArg() == 0 {
		for i := len(os.Getenv("REDO_VERBOSE")); i > 0; i-- {
			verbosity.Set("true")
		}
	}

	if debug.NArg() == 0 {
		if len(os.Getenv("REDO_DEBUG")) > 0 {
			debug.Set("true")
		}
	}

	if s := shArgs; s != "" {
		os.Setenv("REDO_SHELL_ARGS", s)
		redux.ShellArgs = s
	}

	// if shell args are set, ensure that at least minimal verbosity is also set.
	if redux.ShellArgs != "" && (verbosity.NArg() == 0) {
		verbosity.Set("true")
	}

	// Set explicit options to avoid clobbering environment inherited options.
	if n := verbosity.NArg(); n > 0 {
		os.Setenv("REDO_VERBOSE", strings.Repeat("x", n))
		redux.Verbosity = n
	}

	if n := debug.NArg(); n > 0 {
		os.Setenv("REDO_DEBUG", "true")
		redux.Debug = true
	}

	// If no arguments are specified, use run default target if its .do file exists.
	// Otherwise, print usage and exit.
	if len(targets) == 0 && os.Getenv("REDO_DEPTH") == "" {
		if found, err := fileutils.FileExists(DEFAULT_DO); err != nil {
			return err
		} else if found {
			targets = append(targets, DEFAULT_TARGET)
		} else {
			targets = append(targets, "all")
		}
	}

	wd, err := os.Getwd()
	if err != nil {
		return err
	}

	// It *is* slower to reinitialize for each target, but doing
	// so guarantees that a single redo call with multiple targets that
	// potentially have differing roots will work correctly.
	for _, path := range targets {
		if file, err := redux.NewFile(wd, path); err != nil {
			return err
		} else {
			file.IsTaskFlag = isTask
			if err := file.Redo(); err != nil {
				return err
			}
		}
	}

	return nil
}