Example #1
0
func main() {
	readline.Completer = interactiveCompletion
	spec := options.NewOptions(optionSpec).SetParseCallback(myParse)
	opt := spec.Parse(os.Args[1:])
	args := opt.Leftover
	if len(args) > 0 {
		spawnedProgram = filepath.Base(args[0])
	}
	if !importIgnoreRE(ignoreRe) {
		os.Exit(1)
	}
	if !importSnippet(snippet) {
		os.Exit(1)
	}
	openLog()

	if len(args) == 0 || pipe {
		prolixPipe()
	} else {
		prolixSpawn(args)
	}

	if verbose {
		fmt.Printf("Done. Suppressed %d/%d lines.\n",
			linesSuppressed, linesTotal)
	}
}
Example #2
0
func main() {
	spec := options.NewOptions(mySpec).SetParseCallback(MyParseCallback)
	opt := spec.Parse(os.Args[1:])

	fmt.Printf("I will concatenate the files: %q\n", opt.Extra)
	if n {
		fmt.Println("I will number each line")
	}
	if e {
		fmt.Println("I will escape each line")
	}
	if r != 1 {
		fmt.Printf("I will repeat each line %d times\n", r)
	}
	if v > 0 {
		fmt.Printf("I will be verbose (level %d)\n", v)
	}
	fmt.Printf("Input charset: %s\n", in)
	fmt.Printf("Output charset: %s\n", out)

	fmt.Printf("Chance for a cookie: %.2f\n", c)
	var max = big.NewInt(1000)
	rnd, _ := rand.Int(rand.Reader, max)
	if cInt > rnd.Int64() {
		fmt.Println("*** You got a cookie! Yay! ***")
	}
}
Example #3
0
func main() {
	spec := options.NewOptions(mySpec)
	opt := spec.Parse(os.Args[1:])

	fmt.Printf("I will concatenate the files: %q\n", opt.Extra)
	if opt.GetBool("number") {
		fmt.Println("I will number each line")
	}
	if opt.GetBool("escape") {
		fmt.Println("I will escape each line")
	}
	if r := opt.GetInt("repeat"); r != 1 {
		fmt.Printf("I will repeat each line %d times\n", r)
	}
	if v := opt.GetInt("verbose"); v > 0 {
		fmt.Printf("I will be verbose (level %d)\n", v)
	}
	fmt.Printf("Input charset: %s\n", opt.Get("input-encoding"))
	fmt.Printf("Output charset: %s\n", opt.Get("output-encoding"))
	authors := options.GetAll("--author", opt.Flags) // Note, you need "--".
	if len(authors) > 0 {
		fmt.Printf("You like these authors. I'll tell you if I see them: %q\n", authors)
	}

	fmt.Printf("For reference, here are the flags you gave me: %v\n", opt.Flags)
}
Example #4
0
func main() {
	spec := options.NewOptions(flags)
	opt := spec.Parse(os.Args[1:])
	nonFlags := append(opt.Extra, opt.Leftover...)

	if opt.GetBool("help") {
		spec.PrintUsageAndExit("")
	}

	var abc *spellabc.Encoding
	switch strings.ToLower(opt.Get("alphabet")) {
	case "jan":
		abc = spellabc.JanAlphabet
	case "lapd":
		abc = spellabc.LapdAlphabet
	case "nato":
		abc = spellabc.NatoAlphabet
	case "westernunion":
		abc = spellabc.WesternUnionAlphabet
	case "usfinancial":
		abc = spellabc.UsFinancialAlphabet
	default:
		spec.PrintUsageAndExit("Unknown alphabet: " + opt.Get("alphabet"))
	}

	if len(nonFlags) < 1 {
		spec.PrintUsageAndExit("You must supply a STRING to convert.")
	}

	for _, input := range nonFlags {
		if opt.GetBool("verbose") {
			fmt.Printf("%s  =  ", input)
		}
		fmt.Println(abc.Encode(input))
	}
}
Example #5
0
func main() {
	var cfg *ini.File
	var backup bool
	var reload bool
	var err error

	s := options.NewOptions(SPEC)

	// Check if options isn't passed
	if len(os.Args[1:]) <= 0 {
		s.PrintUsageAndExit("No option specified")
	}

	opts := s.Parse(os.Args[1:])
	grace := ""

	// Print version and exit
	if opts.GetBool("version") {
		fmt.Println("Memento server " + VERSION)
		os.Exit(0)
	}

	// Print help and exit
	if opts.GetBool("help") {
		s.PrintUsageAndExit("Memento server " + VERSION)
	}

	// Check backup or restore operation (mandatory)
	if opts.GetBool("backup") && opts.GetBool("restore") {
		// If backup and restore options are passed in the same session, print help and exit
		s.PrintUsageAndExit("Cannot perform a backup and restore operations in the same session")
	}

	// Read grace (mandatory)
	if opts.GetBool("hour") {
		grace = "hour"
	} else if opts.GetBool("day") {
		grace = "day"
	} else if opts.GetBool("week") {
		grace = "week"
	} else if opts.GetBool("month") {
		grace = "month"
	} else {
		// If grace is not selected, print help and exit
		s.PrintUsageAndExit("No grace selected")
	}

	if opts.GetBool("reload-dataset") {
		reload = true
	} else {
		reload = false
	}

	if opts.GetBool("backup") {
		backup = true
		cfg, err = ini.Load([]byte{}, opts.Get("backup"))
	} else if opts.GetBool("restore") {
		backup = false
		cfg, err = ini.Load([]byte{}, opts.Get("restore"))
	}

	if err != nil {
		fmt.Println("Error about reading config file:", err)
		os.Exit(1)
	}

	repository := cfg.Section("general").Key("repository").String()
	checkStructure(repository)

	loglevel, _ := logging.LogLevel(cfg.Section("general").Key("log_level").String())
	log := setLog(loglevel, cfg.Section("general").Key("log_file").String())

	log.Info("Started version " + VERSION)
	log.Debug("Grace selected: " + grace)

	if backup {
		server.Backup(log, cfg, grace, reload)
	} else {
		server.Restore(log, cfg, grace)
	}

	log.Info("Ended version " + VERSION)
}
Example #6
0
func main() {
	var log *logging.Logger
	var port, listen, address string

	s := options.NewOptions(SPEC)

	// Check if options isn't passed
	if len(os.Args[1:]) <= 0 {
		s.PrintUsageAndExit("No option specified")
	}

	opts := s.Parse(os.Args[1:])

	// Print version and exit
	if opts.GetBool("version") {
		fmt.Println("Memento client " + VERSION)
		os.Exit(0)
	}

	// Print help and exit
	if opts.GetBool("help") {
		s.PrintUsageAndExit("Memento client " + VERSION)
	}

	// Enable debug
	if opts.GetBool("debug") {
		log = setLog(true)
	} else {
		log = setLog(false)
	}

	// Get port to listen
	if opts.GetBool("port") {
		port = opts.Get("port")
	} else {
		log.Fatal("No port specified")
		os.Exit(1)
	}

	// Get address to listen
	if opts.GetBool("listen") {
		if addr := net.ParseIP(opts.Get("listen")); addr != nil {
			listen = addr.String()
		} else {
			log.Fatal("Invalid IP address")
		}
	}

	if listen == "" {
		log.Debug("Listen on all interfaces")
		address = ":" + port
	} else {
		log.Debug("Listen on address " + listen)
		address = listen + ":" + port
	}

	if opts.GetBool("ssl") {
		log.Debug("SSL enabled")
		cfg, err := ini.Load([]byte{}, opts.Get("ssl"))
		if err != nil {
			// handle error
			log.Fatalf("Error: %v\n", err)
		}

		client.Serve(log, address, cfg)
	} else {
		client.Serve(log, address, nil)
	}
}