예제 #1
0
func initConfig(args []string) *config {
	getopt.CommandLine = getopt.New()
	var flags config
	flags.help = getopt.BoolLong("help", 'h', "Display this help")
	flags.priv = getopt.BoolLong("private", 'P', "Private paste flag")
	flags.user = getopt.StringLong("user", 'u', "", "An alphanumeric username of the paste author")
	flags.pass = getopt.StringLong("pass", 'p', "", "Add a password")
	flags.lang = getopt.StringLong("lang", 'l', "Text", "The development language used")
	flags.expire = getopt.StringLong("expire", 'e', "0", "Seconds after which paste will be deleted from server")
	getopt.SetParameters("[FILE...]")
	getopt.CommandLine.Parse(args)
	return &flags
}
예제 #2
0
파일: main.go 프로젝트: sykesm/git-duet
func main() {
	var (
		quiet = getopt.BoolLong("quiet", 'q', "Silence output")
		help  = getopt.BoolLong("help", 'h', "Help")
	)

	getopt.Parse()

	if *help {
		getopt.Usage()
		os.Exit(0)
	}

	output := new(bytes.Buffer)
	cmd := exec.Command("git", "rev-parse", "--show-toplevel")
	cmd.Stdout = output
	if err := cmd.Run(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	hookPath := path.Join(strings.TrimSpace(output.String()), ".git", "hooks", "pre-commit")

	hookFile, err := os.OpenFile(hookPath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, os.ModePerm)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	defer hookFile.Close()

	if _, err = hookFile.WriteString(hook); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	if !*quiet {
		fmt.Printf("git-duet-install-hook: Installed hook to %s\n", hookPath)
	}
}
예제 #3
0
파일: main.go 프로젝트: vuleetu/misc
package main

import (
	"bytes"
	"code.google.com/p/getopt"
	"encoding/binary"
	"fmt"
	"io/ioutil"
	"log"
	"net"
)

var help = getopt.BoolLong("help", 'h', "Print help")
var sock = getopt.StringLong("sock", 's', "", "UNIX socket domain address")
var cmd = getopt.StringLong("cmd", 'c', "", "Command which will be sent")

func main() {
	getopt.Parse()
	if *help {
		getopt.Usage()
		return
	}

	if *sock == "" || *cmd == "" {
		getopt.Usage()
		return
	}

	conn, err := net.Dial("unix", *sock)
	if err != nil {
		log.Fatalln(err)
예제 #4
0
	"fmt"
	"github.com/freetaxii/freetaxii-server/lib/config"
	"github.com/freetaxii/freetaxii-server/lib/taxiiserver"
	"log"
	"net/http"
	"os"
)

const (
	DEFAULT_CONFIG_FILENAME = "etc/freetaxii.conf"
)

var sVersion = "0.2.1"

var sOptConfigFilename = getopt.StringLong("config", 'c', DEFAULT_CONFIG_FILENAME, "Configuration File", "string")
var bOptHelp = getopt.BoolLong("help", 0, "Help")
var bOptVer = getopt.BoolLong("version", 0, "Version")

func main() {
	getopt.HelpColumn = 35
	getopt.DisplayWidth = 120
	getopt.SetParameters("")
	getopt.Parse()

	if *bOptVer {
		printVersion()
	}

	if *bOptHelp {
		printHelp()
	}
	"github.com/freetaxii/freetaxii-server/lib/config"
	_ "github.com/mattn/go-sqlite3"
	"log"
	"os"
	"strings"
)

const (
	DEFAULT_CONFIG_FILENAME = "../etc/freetaxii.conf"
)

var sVersion = "0.2.1"
var DebugLevel int = 0

var sOptConfigFilename = getopt.StringLong("config", 'c', DEFAULT_CONFIG_FILENAME, "Configuration File", "string")
var bOptListCollection = getopt.BoolLong("list-collections", 0, "List Collections")
var bOptAddCollection = getopt.BoolLong("add-collection", 0, "Add Collections")
var bOptDelCollection = getopt.BoolLong("del-collection", 0, "Delete Collections")
var bOptHelp = getopt.BoolLong("help", 0, "Help")
var bOptVer = getopt.BoolLong("version", 0, "Version")

func main() {
	getopt.HelpColumn = 35
	getopt.DisplayWidth = 120
	getopt.SetParameters("")
	getopt.Parse()

	if *bOptVer {
		printVersion()
	}
예제 #6
0
파일: main.go 프로젝트: sykesm/git-duet
func main() {
	var (
		quiet  = getopt.BoolLong("quiet", 'q', "Silence output")
		global = getopt.BoolLong("global", 'g', "Change global config")
		help   = getopt.BoolLong("help", 'h', "Help")
	)

	getopt.Parse()

	if *help {
		getopt.Usage()
		os.Exit(0)
	}

	configuration, err := duet.NewConfiguration()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	if getopt.NArgs() == 0 {
		gitConfig, err := duet.GetAuthorConfig(configuration.Namespace)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		author, err := gitConfig.GetAuthor()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		printAuthor(author)
		os.Exit(0)
	}

	gitConfig := &duet.GitConfig{
		Namespace: configuration.Namespace,
	}
	if configuration.Global || *global {
		gitConfig.Scope = duet.Global
	}

	pairs, err := duet.NewPairsFromFile(configuration.PairsFile, configuration.EmailLookup)
	if err != nil {
		fmt.Println(err)
		os.Exit(0)
	}

	author, err := pairs.ByInitials(getopt.Arg(0))
	if err != nil {
		fmt.Println(err)
		os.Exit(86)
	}

	if err = gitConfig.SetAuthor(author); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	if err = gitConfig.ClearCommitter(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	if !*quiet {
		printAuthor(author)
	}
}
예제 #7
0
파일: reg.go 프로젝트: knz/reg
func main() {
	ifname := getopt.StringLong("input", 'i', "-", "Set input stream for supplies (default '-', stdin)", "FILE")
	ofname := getopt.StringLong("output", 'o', "-", "Set output stream for reports (default '-', stdout)", "FILE")
	tspec := getopt.StringLong("ticks", 't', "", "Set tick generator (produces tick events)", "SPEC")
	sspec := getopt.StringLong("steps", 's', "", "Set progress indicator (measures steps)", "SPEC")
	mspec := getopt.StringLong("monitor", 'm', "", "Set resource monitor (measures stuff)", "SPEC")
	aspec := getopt.StringLong("actuator", 'a', "", "Set actuator (triggered upon supply exhaustion)", "SPEC")
	gran := getopt.StringLong("granularity", 'g', "0", "Force tick granularity (default 0, disabled)", "N")
	thr := getopt.StringLong("periodic-output", 'p', "none", "Configure periodic output (default none)", "PER")
	help := getopt.BoolLong("help", 'h', "Print this help")
	ver := getopt.BoolLong("version", 0, "Report version number")

	getopt.SetParameters("")
	getopt.Parse()

	/*** -h / -v ***/
	if *help {
		getopt.Usage()
		fmt.Println("\nReport bugs to http://github.com/knz/reg/issues")
		os.Exit(0)
	}

	if *ver {
		fmt.Println("reg (REG-ulator)", version)
		os.Exit(0)
	}

	/*** -i / -o ***/

	var fin, fout *os.File
	var err error

	if *ifname == "-" {
		fin = os.Stdin
	} else {
		fin, err = os.Open(*ifname)
		Assert(err == nil, "-i :", err)
	}

	if *ofname == "-" {
		fout = os.Stdout
	} else {
		fout, err = os.OpenFile(*ofname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
		Assert(err == nil, "-o :", err)
	}

	/*** -g ***/

	g, err := strconv.ParseFloat(*gran, 64)
	Assert(err == nil, "-g :", err)
	Assert(g >= 0, "-g : granularity cannot be negative")

	/*** -p ***/

	throttle_type := reg.OUTPUT_EXPLICIT_ONLY
	throttle_period := float64(0)

	spec_type, spec_flags, spec_arg := split(*thr)
	switch spec_type {
	case "none":
		Assert(spec_flags == "" && spec_arg == "", "-p none does not accept flags/argument")
		throttle_type = reg.OUTPUT_EXPLICIT_ONLY
	case "flood":
		Assert(spec_flags == "" && spec_arg == "", "-p flood does not accept flags/argument")
		throttle_type = reg.OUTPUT_FLOOD
	case "ticks":
		throttle_type = reg.OUTPUT_THROTTLE_TICKS
		if spec_arg != "" {
			throttle_period, err = strconv.ParseFloat(spec_arg, 64)
			Assert(err == nil, "-p ticks :", err)
		}
		Assert(spec_flags == "", "-p ticks does not accept flags")
	case "steps":
		throttle_type = reg.OUTPUT_THROTTLE_STEPS
		if spec_arg != "" {
			throttle_period, err = strconv.ParseFloat(spec_arg, 64)
			Assert(err == nil, "-p steps :", err)
		}
		Assert(spec_flags == "", "-p steps does not accept flags")
	default:
		Assert(false, "invalid syntax for -p")
	}
	Assert(throttle_period >= 0, "-p : period cannot be negative")

	/*** -a ***/

	var a act.Actuator
	spec_type, spec_flags, spec_arg = split(*aspec)
	Assert(spec_flags == "", "-a does not accept flags")
	switch spec_type {
	case "discard":
		Assert(spec_arg == "", "-a discard does not accept argument")
		a = act.MakeDummyActuator()
	case "print":
		var af *os.File
		if spec_arg == "-" || spec_arg == "" {
			af = os.Stdout
		} else {
			af, err = os.OpenFile(spec_arg, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
			Assert(err == nil, "-a :", err)
		}
		a = act.MakePrinterActuator(af)
	case "proc":
		a = act.MakeCommandActuator(cmd.MakeInteractiveCommand(spec_arg))
	case "cmd":
		a = act.MakeCommandActuator(cmd.MakeOneShotCommand(spec_arg))
	default:
		Assert(false, "invalid -a, or -a not specified")
	}

	/*** -t ***/

	var ts ticks.Source
	spec_type, spec_flags, spec_arg = split(*tspec)
	switch spec_type {
	case "instant":
		Assert(spec_flags == "", "-t instant does not accept flags")
		v := float64(0)
		if spec_arg != "" {
			v, err = strconv.ParseFloat(spec_arg, 64)
			Assert(err == nil, "-t instant:", err)
		}
		ts = ticks.MakeDummySource(t.Ticks(v))
	case "time", "ptime", "cmd", "proc":
		stype, ok := flagconv(spec_flags)
		Assert(ok, "invalid flags for -t")
		switch spec_type {
		case "time", "ptime":
			d, err := time.ParseDuration(spec_arg)
			Assert(err == nil, "-t :", err)
			ts = ticks.MakeTimerSource(d, stype, spec_type == "ptype")
		case "cmd":
			ts = ticks.MakeCommandSource(cmd.MakeOneShotCommand(spec_arg), stype)
		case "proc":
			ts = ticks.MakeCommandSource(cmd.MakeInteractiveCommand(spec_arg), stype)
		}
	default:
		Assert(false, "invalid -t, or -t not specified")
	}

	/*** -s ***/

	var ss steps.Source
	spec_type, spec_flags, spec_arg = split(*sspec)
	switch spec_type {
	case "const":
		Assert(spec_flags == "", "-s dummy does not accept flags")
		v := float64(0)
		if spec_arg != "" {
			v, err = strconv.ParseFloat(spec_arg, 64)
			Assert(err == nil, "-s const:", err)
			Assert(v >= 0, "-s const: constant cannot be negative")
		}
		ss = steps.MakeDummySource(t.Steps(v))
	case "cmd", "proc":
		stype, ok := flagconv(spec_flags)
		Assert(ok, "invalid flags for -s")
		switch spec_type {
		case "cmd":
			ss = steps.MakeCommandSource(cmd.MakeOneShotCommand(spec_arg), stype)
		case "proc":
			ss = steps.MakeCommandSource(cmd.MakeInteractiveCommand(spec_arg), stype)
		}
	default:
		Assert(false, "invalid -s, or -s not specified")
	}

	/*** -m ***/

	var m sample.Sampler
	spec_type, spec_flags, spec_arg = split(*mspec)
	switch spec_type {
	case "const":
		Assert(spec_flags == "", "-m const does not accept flags")
		v := float64(0)
		if spec_arg != "" {
			v, err = strconv.ParseFloat(spec_arg, 64)
			Assert(err == nil, "-m const:", err)
		}
		m = sample.MakeDummySampler(t.Stuff(v))
	case "cmd", "proc":
		Assert(spec_flags == "", "-m cmd/proc does not accept flags")
		switch spec_type {
		case "cmd":
			m = sample.MakeCommandSampler(cmd.MakeOneShotCommand(spec_arg))
		case "proc":
			m = sample.MakeCommandSampler(cmd.MakeInteractiveCommand(spec_arg))
		}
	default:
		Assert(false, "invalid -m, or -m not specified")
	}

	d := reg.MakeDomain(ts, ss, a, m)
	d.Start(fin, fout, throttle_type, throttle_period, t.Ticks(g))
	d.Wait()
}
예제 #8
0
파일: main.go 프로젝트: Jdavid1001/git-duet
func main() {
	var (
		quiet  = getopt.BoolLong("quiet", 'q', "Silence output")
		global = getopt.BoolLong("global", 'g', "Change global config")
		help   = getopt.BoolLong("help", 'h', "Help")
	)

	getopt.Parse()

	if *help {
		getopt.Usage()
		os.Exit(0)
	}

	configuration, err := duet.NewConfiguration()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	if getopt.NArgs() == 0 {
		gitConfig, err := duet.GetAuthorConfig(configuration.Namespace)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		author, err := gitConfig.GetAuthor()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		committer, err := gitConfig.GetCommitter()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		if committer == nil {
			committer = author
		}

		printAuthor(author)
		printCommitter(committer)
		os.Exit(0)
	}

	gitConfig := &duet.GitConfig{
		Namespace: configuration.Namespace,
	}
	if configuration.Global || *global {
		gitConfig.Scope = duet.Global
	}

	if getopt.NArgs() <= 2 {
		fmt.Println("must specify more than two sets of initials")
		os.Exit(1)
	}

	pairs, err := duet.NewPairsFromFile(configuration.PairsFile, configuration.EmailLookup)
	if err != nil {
		fmt.Println(err)
		os.Exit(0)
	}

	author, err := pairs.ByInitials(getopt.Arg(0))
	if err != nil {
		fmt.Println(err)
		os.Exit(86)
	}

	if err = gitConfig.SetAuthor(author); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	number_of_committers := getopt.NArgs() - 1
	committers := make([]*duet.Pair, number_of_committers)

	for i := 1; i < getopt.NArgs(); i++ {
		committer, err := pairs.ByInitials(getopt.Arg(i))
		if err == nil {
			committers[i-1] = committer
		} else {
			fmt.Println(err)
			os.Exit(1)
		}
	}

	committer := makeTeamCommitter(committers)

	if err = gitConfig.SetCommitter(committer); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	if !*quiet {
		printAuthor(author)
		printCommitter(committer)
	}
}