Exemple #1
0
func main() {
	var profile, version bool
	flag.BoolVarP(&version, "version", "v", false, "\tShow version")
	flag.BoolVar(&profile, "profile", false, "\tEnable profiler")
	flag.Parse()

	InitConfig()
	Config.MaxResults = 20

	if profile {
		f, err := os.Create("alexandria.prof")
		if err != nil {
			panic(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	// TODO run GenerateIndex() when there is something new

	if version {
		fmt.Println(NAME, VERSION)
		return
	}

	http.HandleFunc("/", mainHandler)
	http.HandleFunc("/stats", statsHandler)
	http.HandleFunc("/search", queryHandler)
	http.HandleFunc("/alexandria.edit", editHandler)
	serveDirectory("/images/", Config.CacheDirectory)
	serveDirectory("/static/", Config.TemplateDirectory+"static")
	http.ListenAndServe("127.0.0.1:41665", nil)
}
Exemple #2
0
func main() {
	logmgr.SetOutput(os.Stderr)
	if flagVerbose {
		logmgr.SetLevel(logrus.DebugLevel)
	} else {
		logmgr.SetLevel(logrus.InfoLevel)
	}

	flag.Parse()
	conf := &config.BuildConfig{
		BuildDir:  flagBuildDir,
		OutputDir: flag.Arg(0),
		Platform:  flagPlatform,
		Arch:      flagArch,
	}

	recipes := flag.Args()[1:]

	// Special case - passing a single 'all' means build all binaries.
	if len(recipes) == 1 && recipes[0] == "all" {
		recipes = builder.AllBinaries()
	}

	log.WithField("recipes", recipes).Info("Starting build")
	err := builder.Build(recipes, conf)
	if err != nil {
		log.WithField("err", err).Error("Error building")
	} else {
		log.Info("Successfully built")
	}
}
Exemple #3
0
func parseFlags() (*cmdConfig, *busltee.Config, error) {
	publisherConf := &busltee.Config{}
	cmdConf := &cmdConfig{}

	cmdConf.RollbarEnvironment = os.Getenv("ROLLBAR_ENVIRONMENT")
	cmdConf.RollbarToken = os.Getenv("ROLLBAR_TOKEN")

	// Connection related flags
	flag.BoolVarP(&publisherConf.Insecure, "insecure", "k", false, "allows insecure SSL connections")
	flag.IntVar(&publisherConf.Retry, "retry", 5, "max retries for connect timeout errors")
	flag.IntVar(&publisherConf.StreamRetry, "stream-retry", 60, "max retries for streamer disconnections")
	flag.Float64Var(&publisherConf.Timeout, "connect-timeout", 1, "max number of seconds to connect to busl URL")

	// Logging related flags
	flag.StringVar(&publisherConf.LogPrefix, "log-prefix", "", "log prefix")
	flag.StringVar(&publisherConf.LogFile, "log-file", "", "log file")
	flag.StringVar(&publisherConf.RequestID, "request-id", "", "request id")

	if flag.Parse(); len(flag.Args()) < 2 {
		return nil, nil, errors.New("insufficient args")
	}

	publisherConf.URL = flag.Arg(0)
	publisherConf.Args = flag.Args()[1:]

	return cmdConf, publisherConf, nil
}
func (cm *ConfigManager) parseFlags() {
	pflag.StringVarP(&cm.Flags.ConfigFile, "configfile", "c", DefaultConfigFile, "Path to config")
	pflag.StringVarP(&cm.Flags.DestHost, "dest-host", "d", "", "Destination syslog hostname or IP")
	pflag.IntVarP(&cm.Flags.DestPort, "dest-port", "p", 0, "Destination syslog port")
	if utils.CanDaemonize {
		pflag.BoolVarP(&cm.Flags.NoDaemonize, "no-detach", "D", false, "Don't daemonize and detach from the terminal")
	} else {
		cm.Flags.NoDaemonize = true
	}
	pflag.StringVarP(&cm.Flags.Facility, "facility", "f", "user", "Facility")
	pflag.StringVar(&cm.Flags.Hostname, "hostname", "", "Local hostname to send from")
	pflag.StringVar(&cm.Flags.PidFile, "pid-file", "", "Location of the PID file")
	// --parse-syslog
	pflag.StringVarP(&cm.Flags.Severity, "severity", "s", "notice", "Severity")
	// --strip-color
	pflag.BoolVar(&cm.Flags.UseTCP, "tcp", false, "Connect via TCP (no TLS)")
	pflag.BoolVar(&cm.Flags.UseTLS, "tls", false, "Connect via TCP with TLS")
	pflag.BoolVar(&cm.Flags.Poll, "poll", false, "Detect changes by polling instead of inotify")
	pflag.Var(&cm.Flags.RefreshInterval, "new-file-check-interval", "How often to check for new files")
	_ = pflag.Bool("no-eventmachine-tail", false, "No action, provided for backwards compatibility")
	_ = pflag.Bool("eventmachine-tail", false, "No action, provided for backwards compatibility")
	pflag.StringVar(&cm.Flags.DebugLogFile, "debug-log-cfg", "", "the debug log file")
	pflag.StringVar(&cm.Flags.LogLevels, "log", "<root>=INFO", "\"logging configuration <root>=INFO;first=TRACE\"")
	pflag.Parse()
	cm.FlagFiles = pflag.Args()
}
func main() {
	pflag.Usage = func() {
		fmt.Printf(`usage: tuplespaced [flags]

Run tuplespace server.

Flags:
`)
		pflag.PrintDefaults()
	}
	pflag.Parse()
	runtime.GOMAXPROCS(*ncpuFlag)

	log.AddFilter("stdout", logLevels[*logLevelFlag], log.NewConsoleLogWriter())
	debug := logLevels[*logLevelFlag] <= log.DEBUG

	log.Info("Starting server on http://%s/tuplespace/", *bindFlag)

	ts := tuplespace.NewTupleSpace(store.NewMemoryStore())

	srv := &http.Server{
		Addr:         *bindFlag,
		Handler:      makeService(ts, debug),
		ReadTimeout:  *readTimeoutFlag,
		WriteTimeout: *writeTimeoutFlag,
	}
	err := srv.ListenAndServe()
	if err != nil {
		fatalf("error: %s\n", err)
	}
}
Exemple #6
0
func main() {
	flag.Usage = func() {
		fmt.Fprint(os.Stderr, Usage)
	}

	flag.IntVarP(&options.Port, "port", "p", 9080, "")

	flag.Parse()

	// Parse base template
	var err error
	options.template, err = template.New("base").Parse(Template)
	if err != nil {
		log.Fatalln("Error parsing HTML template:", err)
	}
	options.Dir = "apidoc"
	// Verify that the wiki folder exists
	_, err = os.Stat(options.Dir)
	if os.IsNotExist(err) {
		log.Fatalln("Directory not found")
	}

	http.Handle("/apidoc/view", commonHandler(WikiHandler))
	http.Handle("/", commonHandler(WikiHandler))

	log.Println("Listening on:", options.Port)
	http.ListenAndServe(fmt.Sprintf(":%d", options.Port), nil)
}
Exemple #7
0
func main() {
	flag.Usage = func() {
		// This is a little weird because I want to insert the correct
		// UTMP/WTMP file names into the Help output, but usually my
		// Help constants are raw string literals, so I had to
		// break it up into a couple chunks and move around some formatting.
		fmt.Fprintf(os.Stderr, "%s %s.  %s %s",
			Help1, utmp.UtmpFile, utmp.WtmpFile, Help2)
		os.Exit(1)
	}
	flag.Parse()

	if *version {
		fmt.Printf("%s\n", Version)
		os.Exit(0)
	}

	switch flag.NArg() {
	case 0:
		uptime(utmp.UtmpFile, utmp.CheckPIDs)
	case 1:
		uptime(flag.Arg(0), 0)
	default:
		fatal.Fatalf("extra operand %s\n", flag.Arg(1))
	}
}
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s", Help)
		os.Exit(1)
	}
	flag.Parse()

	dir, err := os.Getwd()
	if err != nil {
		fatal.Fatalln(err)
	}

	// "To flush all open files on a volume, call FlushFileBuffers with a handle to the volume.
	// The caller must have administrative privileges. For more information, see Running with Special Privileges."
	// https://msdn.microsoft.com/en-us/library/windows/desktop/aa364439(v=vs.85).aspx
	fp := filepath.VolumeName(dir)
	file, err := os.Open(fp)
	if err != nil {
		fatal.Fatalln(err)
	}

	err = syscall.Fsync(syscall.Handle(file.Fd()))
	if err != nil {
		fatal.Fatalln(err)
	}
}
Exemple #9
0
func init() {
	flag.Parse()

	log.PrintDebug = *debug
	log.Fileformat = func(now string, i int) string { return fmt.Sprintf("logs/%[1]s-%02[2]d.log", now, i) }
	log.Init()
	lang.Load()
	config.IndentConfig = *debug
	config.Load()

	if !*disableSafeShutdown {
		c := make(chan os.Signal, 1)
		signal.Notify(c, os.Interrupt, syscall.SIGTERM)
		go func() {
			<-c
			Shutdown("Interrupt/SIGTERM")
		}()
	}

	data, err := ioutil.ReadFile("/etc/hostname")
	if err != nil {
		log.Fatalln("Failed to read hostname: %s", err)
		return
	}
	hostname = strings.TrimSpace(string(data))
}
Exemple #10
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s", Help)
		os.Exit(1)
	}
	flag.Parse()

	if *version {
		fmt.Fprintf(os.Stdout, "%s", Version)
		os.Exit(0)
	}

	if len(flag.Args()) > 0 {
		for i := 0; i < len(flag.Args()); i++ {
			filename := flag.Arg(i)
			_, err := os.Stat(filename)
			if err == nil {
				now := time.Now()
				os.Chtimes(filename, now, now)
			} else if !(*nocreate) {
				f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0644)
				f.Close()
				if err != nil {
					log.Fatal(err)
				}
			}
		}
	}
}
Exemple #11
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s", Help)
		os.Exit(1)
	}

	flag.Parse()

	has_error := false

	switch {
	case *show_version:
		fmt.Fprintf(os.Stdout, "%s", Version)
		os.Exit(0)
	case *check_sum:
		if !check_md5sum() {
			has_error = true
		}
	default:
		if !gen_md5sum() {
			has_error = true
		}
	}

	if has_error {
		os.Exit(1)
	}

	os.Exit(0)
}
Exemple #12
0
// Start the game and then, based on command line input, start up client
// interface listeners. Finally, wait for ^C before exiting.
func main() {
	var local, serve bool
	var endpoint string
	pflag.BoolVarP(&local, "local", "l", true, "run a local interactive REPL")
	pflag.BoolVarP(&serve, "serve", "s", false, "run a networked multiuser server")
	pflag.StringVarP(&endpoint, "endpoint", "e", ":4000", "where to run the networked server")
	pflag.Parse()

	done, events, spellbook := StartGame()

	if serve {
		go ListenTCP(endpoint, events, spellbook)
	}
	if local {
		go ListenLocal(events, spellbook)
	}

	interrupt := make(chan os.Signal)
	signal.Notify(interrupt, os.Interrupt)

	quitting := false
	for !quitting {
		select {
		case <-interrupt:
			events <- &ShutdownEvent{}
		case err := <-done:
			log.Print("main() stopping: ", err)
			quitting = true
		}
	}
}
Exemple #13
0
func main() {
	var port uint
	var etcdAddr, logLevel string

	flag.UintVarP(&port, "port", "p", 19000, "listen port")
	flag.StringVarP(&etcdAddr, "etcd", "e", defaultEtcdAddr, "address of etcd machine")
	flag.StringVarP(&logLevel, "log-level", "l", "warn", "log level")
	flag.Parse()

	if err := logx.DefaultSetup(logLevel); err != nil {
		log.WithFields(log.Fields{
			"error": err,
			"level": logLevel,
		}).Fatal("failed to set up logging")
	}

	etcdClient := etcd.NewClient([]string{etcdAddr})

	if !etcdClient.SyncCluster() {
		log.WithFields(log.Fields{
			"addr": etcdAddr,
		}).Fatal("unable to sync etcd cluster")
	}

	ctx := lochness.NewContext(etcdClient)

	_ = Run(port, ctx)
}
func main() {
	flag.Usage = usage
	flag.Parse()

	if *help {
		usage()
	}

	// Read the configuration
	c, err := config.ReadConfigFromFile(cfgfile, source)
	if err != nil {
		fmt.Printf("Error:: %v\n", err)
		os.Exit(0)
	}

	// Create a Process
	process := &Process{Done: make(chan bool),
		Source:         *source,
		Started:        true,
		PagesFileInfo:  make(map[string]*os.FileInfo),
		AssetsFileInfo: make(map[string]*os.FileInfo),
	}

	// Create output directory if it does not exist
	err = os.Mkdir(c.OutputDirectory, 0755)

	// Generate whole book
	GenerateWholeBook(process)

	// Go into watch mode
	if *watchMode {
		WatchMode(*interval, process)
	}
}
Exemple #15
0
func main() {
	adaptflag.AdaptWithFunc(func(info adaptflag.Info) {
		flag.Var(info.Value, info.Name, info.Usage)
	})

	flag.Parse()
}
Exemple #16
0
//go:generate ostypes main
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s\n", Help)
		return
	}
	flag.Parse()

	if *version {
		fmt.Printf("%s\n", Version)
		return
	}

	toprint := decodeFlags()

	if toprint == 0 {
		toprint = PrintKernelName
	}

	if toprint.isSet(
		(PrintKernelName | PrintNodeName | PrintKernelRelease |
			PrintKernelVersion | PrintMachine)) {

		name, err := genInfo()
		if err != nil {
			fatal.Fatalln("cannot get system name")
		}

		if toprint.isSet(PrintKernelName) {
			print(name.sysname)
		}
		if toprint.isSet(PrintNodeName) {
			print(name.nodename)
		}
		if toprint.isSet(PrintKernelRelease) {
			print(name.release)
		}
		if toprint.isSet(PrintKernelVersion) {
			print(name.version)
		}
		if toprint.isSet(PrintMachine) {
			print(name.machine)
		}
	}

	if toprint.isSet(PrintProcessor) {
		element := Unknown
		if !(toprint == MaxUint && element == Unknown) {
			print(element)
		}
	}

	if toprint.isSet(PrintHardwarePlatform) {
		element := HostOS
		if !(toprint == MaxUint && element == Unknown) {
			print(element)
		}
	}

	fmt.Println()
}
Exemple #17
0
func main() {
	flag.Parse()
	if len(flag.Args()) == 0 {
		year := int(time.Now().Year())
		month := int(time.Now().Month())
		calendar(month, year)
	} else if len(flag.Args()) == 1 {
		year, err := strconv.Atoi(flag.Arg(0))
		if err != nil {
			log.Fatal(err)
		}
		for month := 1; month <= 12; month++ {
			calendar(month, year)
			fmt.Println()
		}
	} else if len(flag.Args()) == 2 {
		month, err := strconv.Atoi(flag.Arg(0))
		if err != nil {
			log.Fatal(err)
		}
		year, err := strconv.Atoi(flag.Arg(1))
		if err != nil {
			log.Fatal(err)
		}
		calendar(month, year)
	}
}
Exemple #18
0
func main() {
	flag.Parse()

	switch {
	case *multiple != "":
		// ugly things about to happen...
		if flag.NArg() > 0 { // means it's using -a
			fmt.Print(performBasename(*multiple, *suffix, *zero)) // pick first from -a

			for _, v := range flag.Args() { // the rest...
				fmt.Print(performBasename(v, *suffix, *zero))
			}

		} else { // means it's using --multiple, split em all
			for _, v := range strings.Split(*multiple, " ") {
				fmt.Print(performBasename(v, *suffix, *zero))
			}
		}
	case *suffix != "": //implies -a
		fmt.Print(performBasename(flag.Args()[0], *suffix, *zero))
	default:
		name := flag.Args()[0]
		suffix := ""
		if flag.NArg() == 2 {
			suffix = flag.Args()[1]
		}
		fmt.Print(performBasename(name, suffix, *zero))
	}

}
Exemple #19
0
func main() {
	var config Config
	flag.BoolVar(&DEBUG, "debug", false, "enable debug logging")
	flag.BoolVar(&QUIET, "quiet", false, "disable output")
	flag.StringVar(&config.FieldSep, "csv-fields-terminated-by", "\t", "field separator")
	flag.StringVar(&config.RowSep, "csv-records-terminated-by", "\n", "row separator")
	flag.StringVar(&config.NullString, "csv-null-string", "\\N", "output string for NULL values")
	flag.BoolVar(&config.DateEpoch, "epoch", true, "output datetime as epoch instead of RFC3339")
	defaults_file := flag.String("defaults-file", "my.cnf", "defaults file")
	defaults_group_suffix := flag.String("defaults-group-suffix", "", "defaults group suffix")
	format := flag.String("format", "json", "output format 'json' or 'csv'")
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: mysqlcsvdump [options] database table > output.json\n\n")
		fmt.Fprintf(os.Stderr, "Reads connection info from ./my.cnf. Use '-' for table to send query in stdin\n\n")
		flag.PrintDefaults()
	}
	flag.Parse()

	args := flag.Args()
	if len(args) < 2 {
		flag.Usage()
		os.Exit(1)
	}
	dsn := getDSN(*defaults_file, "client"+*defaults_group_suffix, args[0])
	rows := getRows(dsn, args[1])
	if *format == "json" {
		NewJsonWriter(&config).WriteRows(rows)
	} else {
		NewCsvWriter(&config).WriteRows(rows)
	}
}
Exemple #20
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s", Help)
		os.Exit(1)
	}
	flag.Parse()

	if *version {
		fmt.Printf("%s", Version)
		os.Exit(0)
	}

	if *unset != "" {
		os.Unsetenv(*unset)
	}

	cmd := new(exec.Cmd)
	cmd.Env = env

	// Check for "-" as an argument, because it means the same as "-i"
	if flag.Arg(0) == "-" {
		cmd.Env = make([]string, 0)
	}

	for i, arg := range flag.Args() {
		if strings.Index(arg, delim) > 0 {
			cmd.Env = append(cmd.Env, arg)
		} else if arg != "-" {
			if *nullEol {
				fatal.Fatalln("cannot specify --null (-0) with command")
			}

			cmd.Path = arg

			cmd.Args = append(cmd.Args, flag.Args()[i:]...)
			cmd.Stdin = os.Stdin
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr

			err := execvp(cmd)
			if err != nil {
				fatal.Fatalln(err)
			}
			return
		}

		i++
	}

	eol := '\n'
	if *nullEol {
		eol = '\x00'
	}

	for _, e := range env {
		fmt.Printf("%s%c", e, eol)
	}

	return
}
Exemple #21
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s", Help)
		os.Exit(1)
	}
	flag.Parse()

	switch {
	case *version:
		fmt.Fprintf(os.Stdout, "%s", Version)
		os.Exit(0)
	case *wrap < 0:
		log.Fatalf("invalid wrap size: %d", *wrap)
	default:
		if len(flag.Args()) == 0 {
			readAndHandle(os.Stdin, decode, ignore, wrap)
		} else {
			for i := 0; i < len(flag.Args()); i++ {
				file, err := os.Open(flag.Args()[i])
				if err != nil {
					log.Fatal(err)
				}
				readAndHandle(file, decode, ignore, wrap)
			}
		}
	}

}
Exemple #22
0
func parseArgs() args {
	result := args{}
	pflag.Usage = usage
	pflag.BoolVarP(&result.options.KeepGoing, "keep-going", "k", false, "")
	pflag.BoolVar(&result.options.CheckAll, "check-all", false, "")
	pflag.StringVarP(&result.scriptFile, "file", "f", "", "")
	verbose := pflag.BoolP("verbose", "v", false, "")
	quiet := pflag.BoolP("quiet", "q", false, "")
	topics := pflag.String("debug", "", "")
	pflag.Parse()
	if *topics != "" {
		result.debugTopics = strings.Split(*topics, ",")
	}

	// argh: really, we just want a callback for each occurence of -q
	// or -v, which decrements or increments verbosity
	if *quiet {
		result.verbosity = 0
	} else if *verbose {
		result.verbosity = 2
	} else {
		result.verbosity = 1
	}

	result.options.Targets = pflag.Args()
	return result
}
Exemple #23
0
func main() {
	var widthstr string
	flag.StringVarP(&widthstr, "width", "w", "100%",
		"Output width. Supports column count, percentage and decimals.")
	flag.Usage = usage
	flag.Parse()

	if len(flag.Args()) == 0 {
		flag.Usage()
		os.Exit(1)
	}

	width := getColumns(widthstr) - 1 // -1 for the reset column
	for _, fpath := range flag.Args() {
		im := aimg.NewImage(width)
		handleErr(im.ParseFile(fpath))

		if terminal.IsTerminal(os.Stdout) {
			fmt.Print(im.BlankReset())
		}
		im.WriteTo(os.Stdout)

		w, h := im.ActualSize()
		fmt.Println("File:", filepath.Base(fpath), "size:", w, "x", h)
	}
}
Exemple #24
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s", Help)
		os.Exit(1)
	}
	flag.Parse()

	switch {
	case *version:
		fmt.Fprintf(os.Stdout, "%s", Version)
		os.Exit(0)
	case *multiple:
		for _, v := range flag.Args() {
			dir := baseName(v, *suffix, *zero)
			fmt.Print(dir)
		}
	case *suffix != "":
		// Implies --multiple/-a
		for _, v := range flag.Args() {
			dir := baseName(v, *suffix, *zero)
			fmt.Print(dir)
		}
	default:
		dir := baseName(flag.Args()[0], *suffix, *zero)
		fmt.Print(dir)
	}
}
Exemple #25
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s", Help)
		os.Exit(1)
	}
	flag.Parse()

	if *version {
		fmt.Printf("%s\n", Version)
		os.Exit(0)
	}

	args := flag.Args()
	if flag.NArg() == 0 {
		args = []string{"y"}
	}

	for {
		for i, arg := range args {
			os.Stdout.WriteString(arg)

			if i == len(args)-1 {
				os.Stdout.Write(LineFeed)
			} else {
				os.Stdout.Write(Space)
			}
		}
	}
}
Exemple #26
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "fsping: check responsiveness of mounted filesystems\n\n")
		flag.PrintDefaults()
	}
	flag.Parse()
	fsnum := 0
	fsch := make(chan fs_t)

	fsmap := readmounts()

	args := flag.Args()

	// if extra args were specified keep only filesystems listed
	if len(args) > 0 {
	L:
		for fs, _ := range fsmap {
			for _, a := range args {
				if fs == a {
					continue L
				}
			}
			delete(fsmap, fs)
		}
	}

	// fire them up
	for _, fs := range fsmap {
		fsnum += 1
		// fire off a goroutine for each mounted nfs
		// filesystem. fsch is used for completion
		// notifications
		go statit(fs, fsch)
	}

	// timeout ticker
	tick := time.Tick(*timeout)

	// collect results
	for fsnum > 0 {
		select {
		case fs := <-fsch:
			if *verbose || fs.err != nil {
				fmt.Println(fs)
			}
			fsmap[fs.path] = fs
			fsnum -= 1
		case <-tick:
			// ticker has kicked in, print timeout
			// messages for filesystems that haven't
			// finished
			for _, fs := range fsmap {
				if !*quiet && !fs.done {
					fmt.Println(fs)
				}
			}
			os.Exit(1)
		}
	}
}
Exemple #27
0
func main() {
	flag.Parse()
	if len(flag.Args()) == 0 {
		log.Fatal("need query")
	}
	args := flag.Args()
	if !*retweets {
		args = append(args, "-rt")
	}
	search := url.QueryEscape(strings.Join(args, " "))
	query := fmt.Sprintf("%s?q=%s&count=%d", twSearchBase, search, *resnum)
	for {
		tw, err := twitquery(query)
		if err != nil {
			log.Fatal(err)
		}
		r := tw.Statuses
		for i := range r {
			if *reverse {
				fmt.Println(r[i])
			} else {
				fmt.Println(r[len(r)-i-1])
			}
		}
		if !*follow { // if not in follow mode we are done
			break
		}
		query = twSearchBase + tw.Meta.RefreshUrl
		time.Sleep(*followDelay)
	}
}
Exemple #28
0
func main() {
	var file *string = flag.StringP("config", "c", "", "Config file to use")
	flag.Parse()

	setupInflux()

	alerts := []Alert{}

	data, _ := ioutil.ReadFile(*file)
	err := yaml.Unmarshal(data, &alerts)
	if err != nil {
		panic(err)
	}

	if os.Getenv("DEBUG") == "true" {
		fmt.Printf("%+v\n", alerts)
	}

	setupSlack()
	setupHipchat()
	done := make(chan bool)
	for _, alert := range alerts {
		go func(alert Alert) {
			for {
				alert.Run()
				time.Sleep(time.Duration(alert.Interval) * time.Second)
			}
		}(alert)
	}
	<-done // wait
}
Exemple #29
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s\n", HELP)
		return
	}
	flag.Parse()

	if *version {
		fmt.Printf("%s\n", VERSION)
		return
	}

	silent := *quiet1 || *quiet2

	si := os.Stdin.Fd()
	tty, err := ttyname.TtyName(si)
	if !silent {
		if err == ttyname.NotTty {
			fmt.Println("not a tty")
			os.Exit(1)
		}
		if tty != "" {
			fmt.Println(tty)
			return
		} else {
			fmt.Println("tty")
		}
	}

	if err != nil {
		os.Exit(1)
	}
}
Exemple #30
0
func main() {
	var profile, version bool
	flag.BoolVarP(&version, "version", "v", false, "\tShow version")
	flag.BoolVar(&profile, "profile", false, "\tEnable profiler")
	flag.Parse()

	InitConfig()

	if profile {
		f, err := os.Create("alexandria.prof")
		if err != nil {
			panic(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	// TODO run when there is something new render.GenerateIndex()

	if version {
		fmt.Println(NAME, VERSION)
		return
	}

	err := qml.Run(run)
	if err != nil {
		panic(err)
	}
}