Beispiel #1
0
func fwk_run_cmd_build(cmd *commander.Command, args []string) error {
	var err error
	n := "fwk-app-" + cmd.Name()

	fnames := make([]string, 0, len(args))
	for _, arg := range args {
		if arg == "" {
			continue
		}
		if arg[0] == '-' {
			continue
		}
		fnames = append(fnames, arg)
	}

	if len(fnames) <= 0 {
		return fmt.Errorf("%s: you need to give a list of files or a directory", n)
	}

	bldr, err := builder.NewBuilder(fnames...)
	if err != nil {
		return err
	}

	if o := cmd.Flag.Lookup("o").Value.Get().(string); o != "" {
		bldr.Name = o
	}

	err = bldr.Build()
	if err != nil {
		return err
	}

	return err
}
Beispiel #2
0
func fwk_run_cmd_run(cmd *commander.Command, args []string) error {
	var err error

	n := "fwk-app-" + cmd.Name()

	subargs := make([]string, 0, len(args))
	for _, nn := range []string{"l", "evtmax", "nprocs", "cpu-prof"} {
		val := cmd.Flag.Lookup(nn)
		if val == nil {
			continue
		}
		subargs = append(
			subargs,
			fmt.Sprintf("-"+nn+"=%v", val.Value.Get()),
		)
	}

	fnames := make([]string, 0, len(args))
	for _, arg := range args {
		if arg == "" || arg == "--" {
			continue
		}

		if arg[0] == '-' {
			subargs = append(subargs, arg)
			continue
		}

		fnames = append(fnames, arg)
	}

	if len(fnames) <= 0 {
		return fmt.Errorf("%s: you need to give a list of files or a directory", n)
	}

	bldr, err := builder.NewBuilder(fnames...)
	if err != nil {
		return err
	}

	if o := cmd.Flag.Lookup("o").Value.Get().(string); o != "" {
		bldr.Name = o
	}

	err = bldr.Build()
	if err != nil {
		return err
	}

	bin := bldr.Name
	if !filepath.IsAbs(bin) {
		pwd, err := os.Getwd()
		if err != nil {
			return err
		}
		bin = filepath.Join(pwd, bin)
	}

	if !cmd.Flag.Lookup("k").Value.Get().(bool) {
		defer os.Remove(bin)
	}

	sub := exec.Command(bin, subargs...)
	sub.Stdout = os.Stdout
	sub.Stderr = os.Stderr
	sub.Stdin = os.Stdin

	err = sub.Run()

	return err
}