Example #1
0
func main() {

	if len(os.Args) < 2 {
		fmt.Fprintf(os.Stderr, "Usage: %s -h for help\n", os.Args[0])
		os.Exit(1)
	}

	config_file := goopt.String([]string{"-c", "--config"}, "nrpe.cfg",
		"config file to use")
	//the first option, will be the default, if the -m isnt given
	run_mode := goopt.Alternatives([]string{"-m", "--mode"},
		[]string{"foreground", "daemon", "systemd"}, "operating mode")
	goopt.Parse(nil)

	//implement different run modes..
	fmt.Println(*run_mode)
	config_obj := new(read_config.ReadConfig)
	config_obj.Init(*config_file)
	err := config_obj.ReadConfigFile()
	common.CheckError(err)
	//extract the commands command[cmd_name] = "/bin/foobar"
	config_obj.ReadCommands()
	config_obj.ReadPrivileges()
	//TODO check for errors
	//what we gonna do with the group?
	pwd := drop_privilege.Getpwnam(config_obj.Nrpe_user)
	drop_privilege.DropPrivileges(int(pwd.Uid), int(pwd.Gid))
	//we have to read it from config
	service := ":5666"
	err = setupSocket(4, service, config_obj)
	common.CheckError(err)
}
Example #2
0
func main() {
	hostEnv := os.Getenv("HOST")
	portEnv := os.Getenv("PORT")

	// default to environment variable values (changes the help string :( )
	if hostEnv == "" {
		hostEnv = "*"
	}

	p := 8080
	if portEnv != "" {
		p, _ = strconv.Atoi(portEnv)
	}

	goopt.Usage = usage

	// server mode options
	host := goopt.String([]string{"-h", "--host"}, hostEnv, "host ip address to bind to")
	port := goopt.Int([]string{"-p", "--port"}, p, "port to listen on")

	// cli mode
	vendor := goopt.String([]string{"-v", "--vendor"}, "", "vendor for cli generation")
	status := goopt.String([]string{"-s", "--status"}, "", "status for cli generation")
	color := goopt.String([]string{"-c", "--color", "--colour"}, "", "color for cli generation")
	goopt.Parse(nil)

	args := goopt.Args

	// if any of the cli args are given, or positional args remain, assume cli
	// mode.
	if len(args) > 0 || *vendor != "" || *status != "" || *color != "" {
		cliMode(*vendor, *status, *color, args)
		return
	}
	// normalize for http serving
	if *host == "*" {
		*host = ""
	}

	http.HandleFunc("/v1/", buckle)
	http.HandleFunc("/favicon.png", favicon)
	http.HandleFunc("/", index)

	log.Println("Listening on port", *port)
	http.ListenAndServe(*host+":"+strconv.Itoa(*port), nil)
}
Example #3
0
func main() {

	if len(os.Args) < 2 {
		fmt.Printf("%s -h for help\n", os.Args[0])
		os.Exit(1)
	}

	var host = goopt.String([]string{"-H", "--host"}, "127.0.0.1", "The remote host running NRPE-Server")
	var port = goopt.Int([]string{"-p", "--port"}, 5666, "The remote port on which the NRPE-server listens")
	var transport = goopt.Int([]string{"-t", "--transport"}, 0, "Transport type: 0 - clear, 1 - ssl, 2 -ssh")
	var command = goopt.String([]string{"-c", "--command"}, "version",
		"The check command defined in the nrpe.cfg file you would like to trigger")

	goopt.Parse(nil)
	service := fmt.Sprintf("%s:%d", *host, *port)
	conn := prepareConnection(service, *transport)
	pkt_to_send := common.PrepareToSend(*command, common.QUERY_PACKET)
	err := common.SendPacket(conn, pkt_to_send)
	common.CheckError(err)
	response_from_command, _ := common.ReceivePacket(conn)
	fmt.Println(string(response_from_command.CommandBuffer[:]))
	os.Exit(int(response_from_command.ResultCode))
}
Example #4
0
func init() {
	goopt.Description = func() string {
		return "conchk v" + goopt.Version
	}
	goopt.Author = "Bruce Fitzsimons <*****@*****.**>"
	goopt.Version = "0.3"
	goopt.Summary = "conchk is an IP connectivity test tool designed to validate that all configured IP connectivity actually works\n " +
		"It reads a list of tests and executes them, in a parallel manner, based on the contents of each line" +
		"conchk supports tcp and udp based tests (IPv4 and IPv6), at this time.\n\n" +
		"==Notes==\n" +
		"* The incuded Excel sheet is a useful way to create and maintain the tests\n" +
		"* testing a range of supports is supported. In this case the rules for a successful test are somewhat different\n" +
		"** If one of the ports gets a successful connect, and the rest are refused (connection refused) as nothing is listening\n" +
		"\tthen this is considered to be a successful test of the range. This is the most common scenario in our experience;\n" +
		"\tthe firewalls and routing are demonstrably working, and at least one destination service is ok. If you need all ports to work\n" +
		"\tthen consider using individual tests\n" +
		"* If all tests for this host pass, then conchk will exit(0). Otherwise it will exit(1)\n" +
		"* conchk will use the current hostname, or the commandline parameter, to find the tests approprate to execute - matches on field 3.\n" +
		"\tThis means all the tests for a system, or project can be placed in one file\n" +
		"* The .csv output option will write a file much like the input file, but with two additional columns and without any comments\n" +
		"\t This file can be fed back into conchk without error.\n\n" +
		"See http://bwooce.github.io/conchk/ for more information.\n\n(c)2013 Bruce Fitzsimons.\n\n"

	Hostname, _ := os.Hostname()

	params.Debug = goopt.Flag([]string{"-d", "--debug"}, []string{}, "additional debugging output", "")
	params.TestsFile = goopt.String([]string{"-T", "--tests"}, "./tests.conchk", "test file to load")
	params.OutputFile = goopt.String([]string{"-O", "--outputcsv"}, "", "name of results .csv file to write to. A pre-existing file will be overwritten.")
	params.MyHost = goopt.String([]string{"-H", "--host"}, Hostname, "Hostname to use for config lookup")
	params.MaxStreams = goopt.Int([]string{"--maxstreams"}, 8, "Maximum simultaneous checks")
	params.Timeout = goopt.String([]string{"--timeout"}, "5s", "TCP connectivity timeout, UDP delay for ICMP responses")

	semStreams = make(semaphore, *params.MaxStreams)
	runtime.GOMAXPROCS(runtime.NumCPU())

}
Example #5
0
func main() {
	configFile := goopt.String([]string{"--config"}, "./config.json", "Configuration File")
	var action = goopt.String([]string{"--action"}, "", "Action to run")
	var file = goopt.String([]string{"--file"}, "", "File to classify")
	goopt.Description = func() string {
		return "Perceptron 2.0"
	}
	goopt.Version = "2.0"
	goopt.Summary = "Perceptron"
	goopt.Parse(nil)

	json := perceptron.ReadConfig(*configFile)
	if *action == "preprocess" {
		perceptron.RunPreprocessor(&json)
	} else if *action == "train" {
		perceptron.TrainPerceptron(&json)
	} else if *action == "test" {
		perceptron.TestPerceptron(&json)
	} else {
		perceptron.Preprocess(&json, *file, func(vector []string) {
			fmt.Println(perceptron.RunPerceptron(&json, vector))
		})
	}
}
Example #6
0
func init() {
	format = goopt.String([]string{"--fmt", "--format"}, "",
		"Log format (e.g. '$remote_addr [$time_local] \"$request\"')")
	nginxConfig = goopt.String([]string{"--nginx"}, "",
		"Nginx config to look for 'log_format' directive. You also should specify --nginx-format")
	nginxFormat = goopt.String([]string{"--nginx-format"}, "",
		"Name of nginx 'log_format', should be passed with --nginx option")
	aggField = goopt.String([]string{"-a", "--aggregate"}, "request_time",
		"Nginx access log variable to aggregate")
	groupBy = goopt.String([]string{"-g", "--group-by"}, "request",
		"Nginx access log variable to group by")
	groupByRegexp = goopt.String([]string{"-r", "--regexp"}, "",
		"You can specify regular expression to extract exact data from group by data. "+
			"For example, you might want to group by a path inside $request, so you should "+
			"set this option to '^\\S+\\s(.*)(?:\\?.*)?$'.")
	groupByGeneralize = goopt.String([]string{"--generalize"}, "",
		"Regular expression to generalize data. For example to make /foo/123 and /foo/234 equal")
	debug = goopt.Flag([]string{"--debug"}, []string{"--no-debug"},
		"Log debug information", "Do not log debug information")
	jsonOutput = goopt.String([]string{"-o", "--json"}, "",
		"Save result as json encoded file")
}
Example #7
0
// main handles parsing command line arguments and spawning instances of
// findImages()
func main() {
	rand.Seed(time.Now().UTC().UnixNano())

	var interval = goopt.Int([]string{"-i", "--interval"}, 2000,
		"Milliseconds between requests per connection")
	var connections = goopt.Int([]string{"-c", "--connections"}, 4,
		"Number of simultanious connections")
	var directory = goopt.String([]string{"-d", "--directory"}, "images",
		"Directory to save images to")

	goopt.Description = func() string {
		return "Download random images from imgur"
	}
	goopt.Version = "0.0.1"
	goopt.Summary = "Random imgur downloader"
	goopt.Parse(nil)

	// Create requested number of connections.
	for threadNum := 1; threadNum < *connections; threadNum++ {
		go findImages(*interval, *directory, threadNum)
	}
	findImages(*interval, *directory, 0)
}
Example #8
0
import (
	"errors"
	"fmt"
	"github.com/droundy/goopt"
	"github.com/russross/blackfriday"
	"io/ioutil"
	"os"
	"text/template"
)

type TemplateData struct {
	Contents string
}

// Command-line flags
var outpath = goopt.String([]string{"-o", "--out"}, "", "The (optional) path to an output file")
var templatePath = goopt.String([]string{"-t", "--template"}, "", "The path to the template to be used")
var output string

func main() {
	setup()
	input := readInput(goopt.Args)
	if input == nil {
		fmt.Println("No input found")
		os.Exit(1)
	}
	outfile := getOutfile()
	markdown := blackfriday.MarkdownBasic(input)
	if *templatePath != "" {
		tpl, err := loadTemplate(*templatePath)
		if err != nil {
Example #9
0
package main

// test out the goopt package...

import (
	"fmt"
	goopt "github.com/droundy/goopt"
	"strings"
)

var amVerbose = goopt.Flag([]string{"--verbose"}, []string{},
	"output verbosely", "")
var amHappy = goopt.Flag([]string{"-h", "--happy"}, []string{"-u", "--unhappy", "--sad"}, "be happy", "be unhappy")

var foo = goopt.String([]string{"--name"}, "anonymous", "pick your name")
var bar = goopt.String([]string{"-b"}, "BOO!", "pick your scary sound")
var baz = goopt.String([]string{"-o"}, "", "test whether a silent default works")
var speed = goopt.Alternatives([]string{"--speed", "--velocity"},
	[]string{"slow", "medium", "fast"},
	"set the speed")

var words = goopt.Strings([]string{"--word", "--saying", "-w", "-s"}, "word",
	"specify a word to speak")

var width = goopt.Int([]string{"-l", "--length"}, 1, "number of ?s")

func main() {
	goopt.Summary = "silly test program"
	goopt.Parse(nil)
	if *amVerbose {
		fmt.Println("I am verbose.")
Example #10
0
	"os"
	"bufio"
	"github.com/droundy/goopt"
	git "./git/git"
	"./git/plumbing"
	"./util/out"
	"./util/debug"
	"./util/error"
	"./util/help"
	"./iolaus/prompt"
	"./iolaus/test"
	"./iolaus/core"
	hashes "./gotgo/slice(git.Commitish)"
)

var shortlog = goopt.String([]string{"-m","--patch"}, "COMMITNAME",
	"name of commit")

var description = func() string {
	return `
Record is used to name a set of changes and record the patch to the
repository.
`}

func main() {
	goopt.Vars["Verb"] = "Record"
	goopt.Vars["verb"] = "record"
	defer error.Exit(nil) // Must call exit so that cleanup will work!
	help.Init("record changes.", description, core.ModifiedFiles)
	git.AmInRepo("Must be in a repository to call record!")
	//plumbing.ReadTree(git.Ref("HEAD"))
Example #11
0
var Summary = `gostatic path/to/config

Build a site.
`

var showVersion = goopt.Flag([]string{"-V", "--version"}, []string{},
	"show version and exit", "")
var showProcessors = goopt.Flag([]string{"--processors"}, []string{},
	"show internal processors", "")
var showSummary = goopt.Flag([]string{"--summary"}, []string{},
	"print everything on stdout", "")
var showConfig = goopt.Flag([]string{"--show-config"}, []string{},
	"dump config as JSON on stdout", "")
var doWatch = goopt.Flag([]string{"-w", "--watch"}, []string{},
	"watch for changes and serve them as http", "")
var port = goopt.String([]string{"-p", "--port"}, "8000",
	"port to serve on")
var verbose = goopt.Flag([]string{"-v", "--verbose"}, []string{},
	"enable verbose output", "")

// used in Page.Changed()
var force = goopt.Flag([]string{"-f", "--force"}, []string{},
	"force building all pages", "")

func main() {
	goopt.Version = Version
	goopt.Summary = Summary

	goopt.Parse(nil)

	if *showSummary && *doWatch {
		errhandle(fmt.Errorf("--summary and --watch do not mix together well"))
Example #12
0
	}
	if err == io.EOF {
		err = nil
	}
	return
}

//replace slashes and whitespaces with underscore
func stringify(tstring string) (stringified string) {
	str := strings.Replace(tstring, "\"", "", -1)
	str = strings.Replace(str, "/", "_", -1)
	stringified = strings.Replace(str, " ", "_", -1)
	return
}

var opt_conf = goopt.String([]string{"-c", "--config"}, "config file", "path to config file")
var opt_data = goopt.String([]string{"-d", "--data"}, "data csv", "path to data csv file")
var opt_statsname = goopt.String([]string{"-s", "--statsname"}, "nfs", "extending name for the bucket: $basename.nfs")
var opt_mover = goopt.String([]string{"-m", "--datamover"}, "server_2", "extending name for the bucket: $basename.$movername.nfs")

func main() {
	goopt.Version = version
	goopt.Summary = "send emc vnx performance data to graphite"
	goopt.Parse(nil)

	if f, _ := exists(*opt_conf); f == false {
		fmt.Print(goopt.Help())
		fmt.Println("ERROR: config file " + *opt_conf + " doesn't exist")
		return
	}
	c, _ := config.ReadDefault(*opt_conf)
Example #13
0
import (
	"encoding/json"
	"log"
	"net"
	"os"
	"os/exec"
	"os/signal"
	"strconv"
	"syscall"
	"time"
	//"github.com/Syfaro/telegram-bot-api"
	goopt "github.com/droundy/goopt"
	"gopkg.in/go-telegram-bot-api/telegram-bot-api.v4"
)

var param_cfgpath = goopt.String([]string{"-c", "--config"}, "/etc/leicht/default.json", "set config file path")

func usernameInWhitelist(username string, whitelist []string) bool {
	present := false
	for _, item := range whitelist {
		if username == item {
			present = true
		}
	}
	return present
}

func main() {

	goopt.Description = func() string {
		return "Leicht - universal telegram bot"
Example #14
0
package main

import (
	"bytes"
	"log"
	"net"
	"os/exec"
	"regexp"
	"strings"
	"time"

	"github.com/droundy/goopt"
)

var connect = goopt.String([]string{"-s", "--server"}, "127.0.0.1", "Server to connect to (and listen if listening)")
var port = goopt.Int([]string{"-p", "--port"}, 2222, "Port to connect to (and listen to if listening)")

var listen = goopt.Flag([]string{"-l", "--listen"}, []string{}, "Create a listening TFO socket", "")

func main() {

	goopt.Parse(nil)

	// IPv4 only for no real reason, could be v6 by adjusting the sizes
	// here and where it's used
	var serverAddr [4]byte

	IP := net.ParseIP(*connect)
	if IP == nil {
		log.Fatal("Unable to process IP: ", *connect)
	}
Example #15
0
	Version = "0.4.3"
	Summary = "gr [OPTS] string-to-search\n"

	byteNewLine []byte = []byte("\n")

	ignoreCase = goopt.Flag([]string{"-i", "--ignore-case"}, []string{},
		"ignore pattern case", "")
	onlyName = goopt.Flag([]string{"-n", "--filename"}, []string{},
		"print only filenames", "")
	ignoreFiles = goopt.Strings([]string{"-x", "--exclude"}, "RE",
		"exclude files that match the regexp from search")
	singleline = goopt.Flag([]string{"-s", "--singleline"}, []string{},
		"match on a single line (^/$ will be beginning/end of line)", "")
	plaintext = goopt.Flag([]string{"-p", "--plain"}, []string{},
		"search plain text", "")
	replace = goopt.String([]string{"-r", "--replace"}, "",
		"replace found substrings with this string")
	force = goopt.Flag([]string{"--force"}, []string{},
		"force replacement in binary files", "")
	showVersion = goopt.Flag([]string{"-V", "--version"}, []string{},
		"show version and exit", "")
	noIgnoresGlobal = goopt.Flag([]string{"-I", "--no-autoignore"}, []string{},
		"do not read .git/.hgignore files", "")
	verbose = goopt.Flag([]string{"-v", "--verbose"}, []string{},
		"be verbose (show non-fatal errors, like unreadable files)", "")
)

func main() {
	goopt.Author = Author
	goopt.Version = Version
	goopt.Summary = Summary
	goopt.Usage = func() string {
Example #16
0
// Package ftp implements a FTP client as described in RFC 959.
package main

import (
	"fmt"
	goopt "github.com/droundy/goopt"
	ftp "github.com/jlaffaye/ftp"
)

var server_ip = goopt.String([]string{"-h"}, "0.0.0.0", "FTP服务器IP地址")
var server_port = goopt.Int([]string{"-p"}, 21, "FTP服务器端口")
var username = goopt.String([]string{"-u"}, "anonymous", "登陆用户名")
var password = goopt.String([]string{"-k"}, "anonymous", "登陆用户密码")

var dir = goopt.String([]string{"-d"}, "null", "所要查询的目录")
var file = goopt.String([]string{"-f"}, "null", "所要查询的文件名")

func main() {

	goopt.Description = func() string {
		return "Example program for using the goopt flag library."
	}
	goopt.Version = "1.0"
	goopt.Summary = "checker.exe -h 127.0.0.1 -u user -p 123qwe -d /dir -f file1"
	goopt.Parse(nil)

	fmt.Printf("FTP agrs info server_ip[%v]]\n", *server_ip)
	fmt.Printf("FTP agrs info server_port[%v]\n", *server_port)
	fmt.Printf("FTP agrs info username[%v]\n", *username)
	fmt.Printf("FTP agrs info password[%v]\n", *password)
	fmt.Printf("FTP agrs info dir[%v]\n", *dir)
Example #17
0
package main

import (
	"fmt"
	"github.com/droundy/goadmin/ago/compile"
	"github.com/droundy/goadmin/crypt"
	"github.com/droundy/goopt"
	"io"
	"io/ioutil"
	"os"
	"path"
	"strconv"
)

var urlbase = goopt.String([]string{"--url"}, "", "the base of the URL to download from")

var outname = goopt.String([]string{"--output"}, "FILENAME", "the name of the output file")

var source = goopt.String([]string{"--source"}, func() string {
	wd, _ := os.Getwd()
	return wd
}(), "the url where updates will be available")

var keyfile = goopt.String([]string{"--keyfile"}, "FILENAME", "the name of a key file")
var key = ""
var privatekey crypt.PrivateKey
var publickey crypt.PublicKey
var sequence int64

func main() {
	goopt.Parse(func() []string { return []string{} })
Example #18
0
const ndate = 17

func getDefaultAuthor() string {
	args := []string{"var", "GIT_AUTHOR_IDENT"}
	o, err := exec.Command("git", args...).CombinedOutput()
	if err != nil {
		return err.String()
	}
	lines := bytes.SplitN(o, []byte{'\n'}, 2)
	if len(lines[0]) > ndate {
		lines[0] = lines[0][:len(lines[0])-ndate]
	}
	return string(lines[0])
}

var Author = goopt.String([]string{"--author"}, getDefaultAuthor(), "author of this change")

func createName() string {
	*Author = strings.Replace(strings.Replace(strings.Replace(*Author, "\n", " ", -1), "/", "-", -1), "\\", "-", -1)
	return time.SecondsToUTC(time.Seconds()).Format(time.RFC3339) + "--" + *Author
}

func isEntomonHere() bool {
	fi, err := os.Stat(".entomon")
	return err == nil && fi.IsDirectory()
}

func findEntomon() os.Error {
	origd, err := os.Getwd()
	if err != nil {
		// If we can't read our working directory, let's just fail!
Example #19
0
package main

import (
	"os"
	"fmt"
	"exec"
	"github.com/droundy/goopt"
	"path"
	"io/ioutil"
	"../src/util/debug"
	"../src/util/error"
	stringslice "../src/util/slice(string)"
)

var outname = goopt.String([]string{"-o","--output"}, "FILENAME",
	"name of output file")

func main() {
	goopt.Parse(nil)
	if len(goopt.Args) != 1 {
		error.Exit(os.NewError(os.Args[0]+" requires just one argument!"))
	}
	mdf := goopt.Args[0]
	if mdf[len(mdf)-3:] != ".md" {
		error.Exit(os.NewError(mdf+" doesn't end with .md"))
	}
	basename := mdf[0:len(mdf)-3]
	if *outname == "FILENAME" {
		*outname = basename+".html"
	}
	dir,_ := path.Split(*outname)
Example #20
0
//target:entomonitor
package main

import (
	"bufio"
	"fmt"
	"github.com/droundy/goopt"
	"os"
	"έντομο"
)

var action = goopt.Alternatives([]string{"-A", "--action"},
	[]string{"help", "new-issue", "comment"}, "select the action to be performed")
var message = goopt.String([]string{"-m", "--message"}, "", "short message")
var bugid = goopt.String([]string{"-b", "--bug"}, "", "bug ID")

func dieOn(err os.Error) {
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}

var bug = έντομο.Type("bug")

func main() {
	goopt.Parse(func() []string { return nil })
	pname, err := έντομο.ProjectName()
	dieOn(err)
	fmt.Println("Project name is", pname)
	if *action == "help" {
Example #21
0
// This is just a logging function that uses the verbosity flags to
// decide whether or not to log anything.
func log(x ...interface{}) {
	if *amVerbose {
		fmt.Println(x...)
	}
}

var color = goopt.Alternatives([]string{"--color", "--colour"},
	[]string{"default", "red", "green", "blue"},
	"determine the color of the output")

var repetitions = goopt.Int([]string{"-n", "--repeat"}, 1, "number of repetitions")

var username = goopt.String([]string{"-u", "--user"}, "User", "name of user")

var children = goopt.Strings([]string{"--child"}, "name of child", "specify child of user")

func main() {
	goopt.Description = func() string {
		return "Example program for using the goopt flag library."
	}
	goopt.Version = "1.0"
	goopt.Summary = "goopt demonstration program"
	goopt.Parse(nil)
	defer fmt.Print("\033[0m") // defer resetting the terminal to default colors
	switch *color {
	case "default":
	case "red":
		fmt.Print("\033[31m")
Example #22
0
const (
	CONF_FILE = "config.yaml"
	//action
	ACTION_SSH        = 0
	ACTION_SCP        = 1
	ACTION_SYNC_GROUP = 2
	ACTION_SYNC_FILE  = 3
)

type FileSync struct {
	local, dest, post_cmd, group string
}

//Command-line flag
var group = goopt.String([]string{"-g", "--group"}, "default", "name of group")
var command = goopt.String([]string{"-c", "--command"}, "", "predefined command to execute")
var execute = goopt.String([]string{"-e", "--execute"}, "", "command to execute")
var user = goopt.String([]string{"-u", "--user"}, "root", "name of user")
var pwd = goopt.String([]string{"-p", "--password"}, "", "password")
var promptpwd = goopt.Flag([]string{"--prompt-pwd"}, []string{}, "prompt password", "")
var showlist = goopt.Flag([]string{"-l", "--list"}, []string{}, "list all commands available", "")
var silent = goopt.Flag([]string{"-s", "--silent"}, []string{}, "quiet mode", "")

//scp options
var src = goopt.String([]string{"--src"}, "", "source file to push on the remote server")
var dest = goopt.String([]string{"--dest"}, "", "destination where to push on the remote server")
var syncgroup = goopt.String([]string{"--sync-group"}, "", "group to synchronize")
var syncfile = goopt.String([]string{"--sync-file"}, "", "file to synchronize")

func executeSsh(res chan string, server string, command string) {
Example #23
0
package main

import (
	"fmt"
	goopt "github.com/droundy/goopt"
	"github.com/xaviershay/erg"
	"os"
	"strconv"
)

var port = goopt.Int([]string{"-p", "--port"}, 8080, "Port to connect to. Can also be set with RANGE_PORT environment variable.")
var host = goopt.String([]string{"-h", "--host"}, "localhost", "Host to connect to. Can also be set with RANGE_HOST environment variable.")
var ssl = goopt.Flag([]string{"-s", "--ssl"}, []string{"--no-ssl"},
	"Don't use SSL", "Use SSL. Can also be set with RANGE_SSL environment variable.")
var expand = goopt.Flag([]string{"-e", "--expand"}, []string{"--no-expand"},
	"Do not compress results", "Compress results (default)")

func main() {
	if envHost := os.Getenv("RANGE_HOST"); len(envHost) > 0 {
		*host = envHost
	}

	if envSsl := os.Getenv("RANGE_SSL"); len(envSsl) > 0 {
		*ssl = true
	}

	if envPort := os.Getenv("RANGE_PORT"); len(envPort) > 0 {
		x, err := strconv.Atoi(envPort)
		if err == nil {
			*port = x
		} else {
Example #24
0
package main

import (
	"fmt"
	"github.com/droundy/goadmin/ago/compile"
	"github.com/droundy/goadmin/deps"
	"github.com/droundy/goopt"
	"os"
	"syscall"
)

var outname = goopt.String([]string{"-o"}, "FILENAME.go", "the name of the generated go file")

func main() {
	goopt.Parse(func() []string { return []string{} })

	syscall.Umask(0077) // Turn off read/write/execute priviledges for others

	if len(goopt.Args) < 1 {
		fmt.Println("You need to provide a go file argument.")
		os.Exit(1)
	}

	execname := goopt.Args[0] + ".secret"
	e := compile.Compile(execname, goopt.Args)
	if e != nil {
		fmt.Fprintln(os.Stderr, e)
		os.Exit(1)
	}
	if *outname == "FILENAME.go" {
		fmt.Fprintln(os.Stderr, "secretrun requires a -o argument!")
Example #25
0
package main

import (
	git "./git/git"
	"./git/plumbing"
	"./git/porcelain"
	"./iolaus/core"
	"./iolaus/prompt"
	"./util/error"
	"./util/help"
	"github.com/droundy/goopt"
	"os"
)

var stashname = goopt.String([]string{"-m"}, "STASHNAME",
	"name of stash")

var description = func() string {
	return `
Stash is used to undo a set of unrecorded changes, much like git stash.
`
}

func main() {
	goopt.Vars["Verb"] = "Keep"
	goopt.Vars["verb"] = "keep"
	defer error.Exit(nil) // Must call exit so that cleanup will work!
	help.Init("record changes.", description, core.ModifiedFiles)
	git.AmInRepo("Must be in a repository to call record!")
	//plumbing.ReadTree(git.Ref("HEAD"))
Example #26
0
	defer in.Close()

	reader := bufio.NewReaderSize(in, 256)
	line, isPrefix, err := reader.ReadLine()
	for err == nil && !isPrefix && len(result) < max {
		result = append(result, string(line))
		line, isPrefix, err = reader.ReadLine()
	}
	if err != nil && err != io.EOF {
		panic(err)
	}
	return result
}

var host = goopt.String([]string{"-h", "--host"},
	"localhost",
	"the host on which the MongoDB server or the ZeroMQ queue is running")
var port = goopt.String([]string{"-p", "--port"},
	"27017",
	"the port on which the MongoDB server or the ZermMQ queue is running")
var duration = goopt.Int([]string{"-d", "--duration"},
	60,
	"the duration of the test in seconds")
var sourceIdFile = goopt.String([]string{"-s", "--sids"},
	"source_ids.txt",
	"the name of the file that contains the list of UUIDs for sources")
var resourceIdFile = goopt.String([]string{"-r", "--rids"},
	"resource_ids.txt",
	"the name of the file that contains the list of UUIDs for resources")
var metricFile = goopt.String([]string{"-c", "--metrics"},
	"metrics.txt",
Example #27
0
	r1, r2, err1 = syscall.RawSyscall(syscall.SYS_FORK, 0, 0, 0)

	if err != 0 {
		return 0, err1
	}

	// Handle exception for darwin
	if darwin && r2 == 1 {
		r1 = 0
	}

	return r1, 0

}

var config_file = goopt.String([]string{"-c", "--config"}, "/etc/ranger.conf", "config file")
var install_api_key = goopt.String([]string{"-i", "--install-api-key"}, "", "install api key")
var amForeground = goopt.Flag([]string{"--foreground"}, []string{"--background"}, "run foreground", "run background")

func setup_logger() {
	filename := "/var/log/ranger/ranger.log"

	// Create a default logger that is logging messages of FINE or higher to filename, no rotation
	//    log.AddFilter("file", l4g.FINE, l4g.NewFileLogWriter(filename, false))

	// =OR= Can also specify manually via the following: (these are the defaults, this is equivalent to above)
	flw := l4g.NewFileLogWriter(filename, false)
	if flw == nil {
		fmt.Printf("No permission to write to %s, going to switch to stdout only\n", filename)
	} else {
		flw.SetFormat("[%D %T] [%L] (%S) %M")
Example #28
0
	"strings"

	"github.com/droundy/goopt"
	"github.com/ortutay/decloud/conf"
	"github.com/ortutay/decloud/cred"
	"github.com/ortutay/decloud/msg"
	"github.com/ortutay/decloud/node"
	"github.com/ortutay/decloud/services/calc"
	"github.com/ortutay/decloud/services/payment"
	"github.com/ortutay/decloud/services/store"
	"github.com/ortutay/decloud/util"
)

// General flags
var fPort = goopt.Int([]string{"-p", "--port"}, 9443, "")
var fAppDir = goopt.String([]string{"--app-dir"}, "~/.decloud", "")

// var fTestNet = goopt.Flag([]string{"-t", "--test-net"}, []string{"--main-net"}, "Use testnet", "Use mainnet")
var fMaxBalance = goopt.String([]string{"--max-balance"}, ".1BTC", "")

// Cross-service flags
var fMinFee = goopt.String([]string{"--min-fee"}, "calc.calc=.01BTC", "") // TODO(ortutay) unused? remove?
var fMinCoins = goopt.String([]string{"--min-coins"}, "calc.calc=.1BTC", "")
var fMaxWork = goopt.String([]string{"--max-work"}, "calc.calc={\"bytes\": 1000, \"queries\": 100}", "")

// Store service flags
var fStoreDir = goopt.String([]string{"--store:dir"}, "~/.decloud-store", "")
var fStoreMaxSpace = goopt.String([]string{"--store:max-space"}, "1GB", "")
var fStoreGbPricePerMo = goopt.String([]string{"--store:gb-price-per-mo"}, ".001BTC", "")

func main() {
Example #29
0
)

// Actions
var addFlag = goopt.Flag([]string{"-a", "--add"}, nil, "add a task", "")
var editFlag = goopt.Flag([]string{"-e", "--edit"}, nil, "edit a task, replacing its text", "")
var markDoneFlag = goopt.Flag([]string{"-d", "--done"}, nil, "mark the given tasks as done", "")
var markNotDoneFlag = goopt.Flag([]string{"-D", "--not-done"}, nil, "mark the given tasks as not done", "")
var removeFlag = goopt.Flag([]string{"--remove"}, nil, "remove the given tasks", "")
var reparentFlag = goopt.Flag([]string{"-R", "--reparent"}, nil, "reparent task A below task B", "")
var titleFlag = goopt.Flag([]string{"--title"}, nil, "set the task list title", "")
var versionFlag = goopt.Flag([]string{"--version"}, nil, "show version", "")
var infoFlag = goopt.Flag([]string{"-i", "--info"}, nil, "show information on a task", "")
var importFlag = goopt.Flag([]string{"--import"}, nil, "import and synchronise TODO items from source code", "")

// Options
var priorityFlag = goopt.String([]string{"-p", "--priority"}, "medium", "priority of newly created tasks (veryhigh,high,medium,low,verylow)")
var graftFlag = goopt.String([]string{"-g", "--graft"}, "root", "task to graft new tasks to")
var fileFlag = goopt.String([]string{"--file"}, ".todo2", "file to load task lists from")
var legacyFileFlag = goopt.String([]string{"--legacy-file"}, ".todo", "file to load legacy task lists from")
var allFlag = goopt.Flag([]string{"-A", "--all"}, nil, "show all tasks, even completed ones", "")
var summaryFlag = goopt.Flag([]string{"-s", "--summary"}, nil, "summarise tasks to one line", "")
var orderFlag = goopt.String([]string{"--order"}, "priority", "specify display order of tasks (created,completed,text,priority,duration,done)")

func doView(tasks TaskList) {
	order, reversed := OrderFromString(*orderFlag)
	options := &ViewOptions{
		ShowAll:   *allFlag,
		Summarise: *summaryFlag,
		Order:     order,
		Reversed:  reversed,
	}
Example #30
0
package gomakefile

import (
	"fmt"
	"github.com/droundy/goadmin/ago"
	"github.com/droundy/goopt"
	"io/ioutil"
	"os"
	"regexp"
	"strconv"
)

var mymkfile = goopt.String([]string{"--makefile"}, "Makefile", "name of makefile to update")
var mytarget = goopt.String([]string{"--target"}, "TARGET", "name of target we're building")

func SetMakefile(mkfile string) {
	mymkfile = &mkfile
}

func SetTarget(targ string) {
	mytarget = &targ
}

func GoAddDep(dependency string) {
	ago.Import("github.com/droundy/goadmin/gomakefile")
	ago.Declare("var changed_files = make(map[string]bool)")
	ago.Declare("var this_file_changed = false")
	code := "this_file_changed, e = gomakefile.AddDep(" + strconv.Quote(dependency) + ")"
	code += fmt.Sprint("\n\tif this_file_changed { changed_files[`Makefile`] = true }")
	ago.Code(code)
}