func main() { var opts ShieldAgentOpts opts.Log = "Info" if err := goptions.Parse(&opts); err != nil { fmt.Printf("%s\n", err) goptions.PrintHelp() return } if opts.Help { goptions.PrintHelp() os.Exit(0) } if opts.Version { if Version == "" { fmt.Printf("shield-agent (development)%s\n", Version) } else { fmt.Printf("shield-agent v%s\n", Version) } os.Exit(0) } if opts.ConfigFile == "" { fmt.Fprintf(os.Stderr, "You must specify a configuration file via `--config`\n") os.Exit(1) } log.SetupLogging(log.LogConfig{Type: "console", Level: opts.Log}) log.Infof("starting agent") ag := agent.NewAgent() if err := ag.ReadConfig(opts.ConfigFile); err != nil { log.Errorf("configuration failed: %s", err) return } ag.Run() }
func main() { log.Infof("starting schema...") options := struct { Help bool `goptions:"-h, --help, description='Show the help screen'"` Driver string `goptions:"-t, --type, description='Type of database backend (postgres or mysql)'"` DSN string `goptions:"-d,--database, description='DSN of the database backend'"` Version bool `goptions:"-v, --version, description='Display the SHIELD version'"` }{ // No defaults } if err := goptions.Parse(&options); err != nil { fmt.Printf("%s\n", err) goptions.PrintHelp() return } if options.Help { goptions.PrintHelp() os.Exit(0) } if options.Version { if Version == "" { fmt.Printf("shield-schema (development)%s\n", Version) } else { fmt.Printf("shield-schema v%s\n", Version) } os.Exit(0) } if options.Driver == "" { fmt.Fprintf(os.Stderr, "You must indicate which type of database you wish to manage, via the `--type` option.\n") os.Exit(1) } if options.DSN == "" { fmt.Fprintf(os.Stderr, "You must specify the DSN of your database, via the `--database` option.\n") os.Exit(1) } database := &db.DB{ Driver: options.Driver, DSN: options.DSN, } log.Debugf("connecting to %s database at %s", database.Driver, database.DSN) if err := database.Connect(); err != nil { log.Errorf("failed to connect to %s database at %s: %s", database.Driver, database.DSN, err) } if err := database.Setup(); err != nil { log.Errorf("failed to set up schema in %s database at %s: %s", database.Driver, database.DSN, err) return } log.Infof("deployed schema version %d", db.CurrentSchema) }
func init() { err := goptions.Parse(&options) if err != nil || len(options.Remainder) <= 0 || len(options.Verbs) <= 0 { if err != goptions.ErrHelpRequest && err != nil { log.Printf("Error: %s", err) } goptions.PrintHelp() os.Exit(1) } }
func main() { options := struct { Debug bool `goptions:"-x, --debug, description='Enable debugging'"` Verbose bool `goptions:"-v, --verbose, description='Be not quiet with output'"` }{ Debug: false, Verbose: false, } goptions.Parse(&options) // Propagate debug setting to packages client.Debug = &options.Debug // Get auth values from the environment var creds client.Credentials creds.AuthUrl = os.Getenv("OS_AUTH_URL") creds.OSAuth.TenantName = os.Getenv("OS_TENANT_NAME") creds.OSAuth.PasswordCredentials.Username = os.Getenv("OS_USERNAME") creds.OSAuth.PasswordCredentials.Password = os.Getenv("OS_PASSWORD") cacert = os.Getenv("OS_CACERT") // read cacert pool = NewCertPool() for j, root := range test.roots { ok := opts.Roots.AppendCertsFromPEM([]byte(root)) if !ok { t.Errorf("#%d: failed to parse root #%d", i, j) return } } // Set up TLS config conf := &tls.Config{InsecureSkipVerify: true} c, err := client.NewClient(creds, conf) if err != nil { log.Fatal(err) } //osclib.GetVersions(c.Auth) if options.Verbose == true { fmt.Printf("Token.Id=%s\n", c.Token.Id) fmt.Printf("Token.Expires=%s\n", c.Token.Expires) fmt.Printf("Tenant.Id=%s\n", c.Token.Tenant.Id) fmt.Printf("Tenant.Name=%s\n", c.Token.Tenant.Name) } else { fmt.Printf("%s %s\n", c.Token.Id, c.Token.Expires) } }
func main() { err := goptions.Parse(&options) if err != nil || (len(options.FormatFile) <= 0 && len(options.FormatString) <= 0) { if err == nil { err = fmt.Errorf("One of --format-file and --format-string must be specified") } fmt.Printf("Error: %s\n", err) goptions.PrintHelp() fmt.Println("Formatters:") for name, format := range Formats { fmt.Printf("\t\"%s\": %s\n", name, format.Description) } fmt.Printf("Version %s\n", VERSION) return } format, ok := Formats[options.Format] if !ok { log.Fatalf("Unknown format %s", options.Format) } f, err := format.Compiler(formatString()) if err != nil { log.Fatalf("Template invalid: %s", err) } dec := json.NewDecoder(os.Stdin) logFn := NewLogFn(options.Continue) for { var input interface{} err := dec.Decode(&input) if err == io.EOF { break } if err != nil { log.Fatalf("Could not decode input: %s", err) continue } err = f.Execute(os.Stdout, input) if err != nil { logFn("Could not apply input to template: %s", err) continue } io.WriteString(os.Stdout, "\n") } }
func getPluginOptions() (PluginOpts, error) { var opts PluginOpts err := goptions.Parse(&opts) if err != nil { return opts, err } if os.Getenv("DEBUG") != "" && strings.ToLower(os.Getenv("DEBUG")) != "false" && os.Getenv("DEBUG") != "0" { debug = true } if opts.Debug { debug = true } return opts, err }
func main() { supervisor.Version = Version var opts ShielddOpts opts.Log = "Info" if err := goptions.Parse(&opts); err != nil { fmt.Printf("%s\n", err) goptions.PrintHelp() return } if opts.Help { goptions.PrintHelp() os.Exit(0) } if opts.Version { if Version == "" { fmt.Printf("shieldd (development)\n") } else { fmt.Printf("shieldd v%s\n", Version) } os.Exit(0) } if opts.ConfigFile == "" { fmt.Fprintf(os.Stderr, "No config specified. Please try again using the -c/--config argument\n") os.Exit(1) } log.SetupLogging(log.LogConfig{Type: "console", Level: opts.Log}) log.Infof("starting shield daemon") s := supervisor.NewSupervisor() if err := s.ReadConfig(opts.ConfigFile); err != nil { log.Errorf("Failed to load config: %s", err) return } s.SpawnAPI() s.SpawnWorkers() if err := s.Run(); err != nil { log.Errorf("shield daemon failed: %s", err) } log.Infof("stopping daemon") }
func main() { var opts ShieldAgentOpts opts.Log = "Info" if err := goptions.Parse(&opts); err != nil { fmt.Printf("%s\n", err) goptions.PrintHelp() return } log.SetupLogging(log.LogConfig{Type: "console", Level: opts.Log}) log.Infof("starting agent") ag := agent.NewAgent() if err := ag.ReadConfig(opts.ConfigFile); err != nil { log.Errorf("configuration failed: %s", err) return } ag.Run() }
func main() { options := struct { Debug bool `goptions:"-x, --debug, description='Enable debugging'"` Verbose bool `goptions:"-v, --verbose, description='Be not quiet with output'"` }{ Debug: false, Verbose: false, } goptions.Parse(&options) // Propagate debug setting to packages client.Debug = &options.Debug // Get auth values from the environment var creds osclib.Creds c, err := client.NewClient(creds) if err != nil { log.Fatal(err) } fmt.Print("Servers: \n") servers, err := server.List(c, "") if err != nil { log.Fatal(err) } if servers != nil { if options.Verbose == true { fmt.Printf("c: %+v\n\n", *servers) } else { fmt.Printf("c: %+v\n\n", *servers) } } flavors, err := flavor.List(c, "") if err != nil { log.Fatal(err) } // osclib.OutputData([]string{"a","b","c"}, []interface{}(flavors)) for k, v := range flavors.Flavors { fmt.Printf("%d: %s\n", k, v.Id) } }
func main() { var options OptType = OptType{ Debug: false, Verbose: false, } goptions.Parse(&options) // Propagate debug setting to packages client.Debug = &options.Debug if len(os.Args) <= 1 || options.Help { Usage() } // Get our credentials creds, err := GetAuthCreds(options) if err != nil { log.Fatal(err) } // Make a new client with these creds c, err := client.NewClient(creds, nil) if err != nil { log.Fatal(err) } if options.Debug { fmt.Printf("token: %s\n", c.Token) fmt.Printf("servcat: %s\n", c.ServCat) } fmt.Printf("verbs: %+v\n", options.Verbs) // fmt.Printf("obj: %+v\n", options.Show.Verbs) switch options.Verbs { case "listflavors": fmt.Print("Args: ", os.Args[1:], "\n") if len(os.Args) > 1 { if f, ok := ListCmds["flavors"]; ok { err = f(c, &options.ListFlavors) } else { fmt.Printf("Unknown command: %s %s\n", options.Verbs, os.Args[1]) fmt.Print("Args: ", os.Args[1:], "\n") } } else { Usage() } os.Exit(0) case "listservers": if len(os.Args) > 2 { if f, ok := ListCmds["servers"]; ok { err = f(c, &options.ListServers) } else { fmt.Printf("Unknown command: %s %s\n", options.Verbs, os.Args[3]) fmt.Print("Args: ", os.Args[1:], "\n") } } else { Usage() } os.Exit(0) case "show": if len(os.Args) > 2 { if f, ok := ShowCmds[string(options.Show.Verbs)]; ok { err = f(c, &options.Show) } else { fmt.Printf("Unknown command: %s %s\n", options.Verbs, os.Args[3]) fmt.Print("Args: ", os.Args[1:], "\n") } } else { Usage() } os.Exit(0) case "version": if options.Version.Identity { // Identity API versions // osclib.GetVersions(c.Auth) os.Exit(0) } else { fmt.Printf("Version: %s\n", Version) os.Exit(0) } default: fmt.Printf("Unknown verb: %s\n", options.Verbs) Usage() } // attr := make(server.Attr) // attr["name"] = "npd01" // servers, err := server.Show(c, attr) // if err != nil { // log.Fatal(err) // } // fmt.Printf("c: %+v\n\n", *servers) }
"strings" ) // Current version of spruce var VERSION = "0.12.0" // SED MARKER FOR AUTO VERSION BUMPING var printfStdOut = func(format string, args ...interface{}) { fmt.Fprintf(os.Stdout, format, args...) } var printfStdErr = func(format string, args ...interface{}) { fmt.Fprintf(os.Stderr, format, args...) } var getopts = func(o interface{}) { err := goptions.Parse(o) if err != nil { usage() } } var exit = func(code int) { os.Exit(code) } var usage = func() { goptions.PrintHelp() exit(1) } var debug bool
func main() { options := struct { InputFile string `goptions:"-i, --input, description='File to read', obligatory"` TimeLimit int `goptions:"-t, --time, description='Maximum number of timesteps (default: 10)'"` Targetset string `goptions:"-z, --targetset, description='Comma-separated list of metabolite indices'"` Verbosity []bool `goptions:"-v, --verbose, description='Increase verbosity'"` SAT bool `goptions:"-s, --output-sat, description='Output in SAT format instead of human-readable CNF'"` goptions.Help `goptions:"-h, --help, description='Show this help'"` }{ TimeLimit: 10, } err := goptions.Parse(&options) if err != nil { log.Printf("Error: %s", err) goptions.PrintHelp() return } z := []string{} if len(options.Targetset) > 0 { z = strings.Split(options.Targetset, ",") for i, elem := range z { z[i] = strings.TrimSpace(elem) } } matrix, irreversible, err := stoichio.ReadFile(options.InputFile) if err != nil { log.Fatalf("Could not read file: %s", err) } t_in, t_out := make([]int, 0), make([]int, 0) sourceset := make([]int, 0) for i := 0; i < matrix.NumCols(); i++ { col := matrix.Col(i) if len(col.Supp()) != 1 { continue } supp := col.Supp() if col[supp[0]] > 0 || (col[supp[0]] < 0 && !irreversible[i]) { t_in = append(t_in, i) sourceset = append(sourceset, supp[0]) } if col[supp[0]] < 0 || (col[supp[0]] > 0 && !irreversible[i]) { t_out = append(t_out, i) } } if len(options.Verbosity) >= 2 { log.Printf("t_in: %#v", t_in) log.Printf("t_out: %#v", t_out) log.Printf("sourceset: %#v", sourceset) log.Printf("z: %#v", z) } a1 := logic.NewOperation(logic.AND) for i := 0; i < matrix.NumRows(); i++ { if contains(sourceset, i) { a1.PushOperands(logic.NewLeaf(fmt.Sprintf(METABOL, i, 0))) } else { a1.PushOperands(logic.NewOperation(logic.NOT, logic.NewLeaf(fmt.Sprintf(METABOL, i, 0)))) } } a2 := logic.NewOperation(logic.AND) a3 := logic.NewOperation(logic.AND) a4 := logic.NewOperation(logic.AND) a5 := logic.NewOperation(logic.AND) a6 := logic.NewOperation(logic.AND) a7 := logic.NewOperation(logic.AND) a5.PushOperands(generateA5(0, matrix)) a6.PushOperands(generateA6(0, matrix)) for t := 1; t < options.TimeLimit; t++ { a2.PushOperands(generateA2(t, matrix, irreversible)) a3.PushOperands(generateA3(t, matrix, irreversible)) a4.PushOperands(generateA4(t, matrix, irreversible, sourceset)) a5.PushOperands(generateA5(t, matrix)) a6.PushOperands(generateA6(t, matrix)) } a2.PushOperands(generateA2(options.TimeLimit, matrix, irreversible)) a3.PushOperands(generateA3(options.TimeLimit, matrix, irreversible)) a4.PushOperands(generateA4(options.TimeLimit, matrix, irreversible, sourceset)) a7.PushOperands(generateA7(options.TimeLimit, z)...) a := logic.NewOperation(logic.AND, a1, a2, a3, a4, a5, a6) if len(z) > 0 { a.PushOperands(a7) } if options.SAT { sat, table := logic.FormatSAT(a) list := sortTable(table) fmt.Println("Table:") tw := tabwriter.NewWriter(os.Stdout, 4, 4, 1, ' ', tabwriter.AlignRight) for _, v := range list { fmt.Fprintf(tw, "\t%d\t=>\t%s\t\n", v.Id, v.Name) } tw.Flush() fmt.Println("") fmt.Println("SAT:") fmt.Println(sat) } else { if len(options.Verbosity) >= 1 { log.Printf("A1:\n%s", a1) log.Printf("A2:\n%s", a2) log.Printf("A3:\n%s", a3) log.Printf("A4:\n%s", a4) log.Printf("A5:\n%s", a5) log.Printf("A6:\n%s", a6) log.Printf("A7:\n%s", a7) log.Printf("A:\n%s", a) } log.Printf("CNF(A):\n%s", logic.CNF(a)) } }