Ejemplo n.º 1
0
func (tc *targetFromArgs) GetTargets(c *cli.Context) ([]*config.Target, error) {
	var targets []*config.Target

	timeout := config.GetTimeDurationConfig(c, "timeout")
	for _, entry := range c.Args() {
		t, err := config.ParseTarget(entry)
		if err != nil {
			return nil, err
		}
		t.Timeout = timeout
		targets = append(targets, t)
	}
	return targets, nil
}
Ejemplo n.º 2
0
func (tc *targetFromFile) targetsFromReaderWithTimeout(reader io.Reader, timeout time.Duration, noEnv bool) ([]*config.Target, error) {
	var targets []*config.Target
	r := bufio.NewReader(reader)
	for {
		line, err := r.ReadString('\n')
		if err != nil {
			if err == io.EOF {
				break
			}
			return nil, err
		}
		line = strings.Trim(line, "\n\t ")

		if strings.HasPrefix(line, "#") {
			// ignore
			continue
		} else if len(line) == 0 {
			// ignore
			continue
		}

		if !noEnv {
			line = os.ExpandEnv(line)
		}

		t, tErr := config.ParseTarget(line)
		if tErr != nil {
			return nil, fmt.Errorf("could not create target from string %v: %v", line, tErr)
		}

		t.Timeout = timeout
		targets = append(targets, t)
	}

	return targets, nil
}