// New creates a new Sup. The io.Writer provided to this function will // receive the output of the sup command. func New(w io.Writer, wdir string) (*Sup, error) { // load the supfile conf, err := stackup.NewSupfile(fmt.Sprintf("%s/Supfile", wdir)) if err != nil { return nil, err } // create new Stackup app. app, err := stackup.New(conf) if err != nil { return nil, err } return &Sup{Stackup: app, writer: w, config: conf}, nil }
func main() { flag.Parse() if showHelp { fmt.Fprintln(os.Stderr, ErrUsage, "\n\nOptions:") flag.PrintDefaults() return } if showVersion { fmt.Fprintln(os.Stderr, sup.VERSION) return } conf, err := sup.NewSupfile(supfile) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } // Parse network and commands to be run from args. network, commands, err := parseArgs(conf) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } // --only option to filter hosts if onlyHosts != "" { expr, err := regexp.CompilePOSIX(onlyHosts) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } var hosts []string for _, host := range network.Hosts { if expr.MatchString(host) { hosts = append(hosts, host) } } if len(hosts) == 0 { fmt.Fprintln(os.Stderr, fmt.Errorf("no hosts match --only '%v' regexp", onlyHosts)) os.Exit(1) } network.Hosts = hosts } // --except option to filter out hosts if exceptHosts != "" { expr, err := regexp.CompilePOSIX(exceptHosts) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } var hosts []string for _, host := range network.Hosts { if !expr.MatchString(host) { hosts = append(hosts, host) } } if len(hosts) == 0 { fmt.Fprintln(os.Stderr, fmt.Errorf("no hosts left after --except '%v' regexp", onlyHosts)) os.Exit(1) } network.Hosts = hosts } // Create new Stackup app. app, err := sup.New(conf) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } // Run all the commands in the given network. err = app.Run(network, commands...) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } }