Ejemplo n.º 1
0
func Test_Register(t *testing.T) {
	ifs := &ItchFS{}
	assert.NoError(t, eos.RegisterHandler(ifs))
	defer eos.DeregisterHandler(ifs)
	assert.Error(t, eos.RegisterHandler(ifs))
}
Ejemplo n.º 2
0
func main() {
	app.UsageTemplate(kingpin.CompactUsageTemplate)
	app.Flag("ignore", "Glob patterns of files to ignore when diffing").StringsVar(&ignoredPaths)

	app.HelpFlag.Short('h')
	if builtAt != "" {
		epoch, err := strconv.ParseInt(builtAt, 10, 64)
		must(err)
		versionString = fmt.Sprintf("%s, built on %s", version, time.Unix(epoch, 0).Format("Jan _2 2006 @ 15:04:05"))
	} else {
		versionString = fmt.Sprintf("%s, no build date", version)
	}
	if commit != "" {
		versionString = fmt.Sprintf("%s, ref %s", versionString, commit)
	}
	app.Version(versionString)
	app.VersionFlag.Short('V')
	app.Author("Amos Wenger <*****@*****.**>")

	cmd, err := app.Parse(os.Args[1:])
	if err != nil {
		ctx, _ := app.ParseContext(os.Args[1:])
		app.FatalUsageContext(ctx, "%s\n", err.Error())
	}

	if *appArgs.timestamps {
		log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds)
	} else {
		log.SetFlags(0)
	}
	log.SetOutput(os.Stdout)

	eos.RegisterHandler(&itchfs.ItchFS{
		ItchServer: *appArgs.address,
	})

	if *appArgs.quiet {
		*appArgs.noProgress = true
		*appArgs.verbose = false
	}

	if !isTerminal() {
		*appArgs.noProgress = true
	}
	comm.Configure(*appArgs.noProgress, *appArgs.quiet, *appArgs.verbose, *appArgs.json, *appArgs.panic, *appArgs.assumeYes, *appArgs.beeps4Life)
	if !isTerminal() {
		comm.Debug("Not a terminal, disabling progress indicator")
	}

	setupHTTPDebug()

	if *appArgs.cpuprofile != "" {
		f, err := os.Create(*appArgs.cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	switch kingpin.MustParse(cmd, err) {
	case dlCmd.FullCommand():
		dl(*dlArgs.url, *dlArgs.dest)

	case cpCmd.FullCommand():
		cp(*cpArgs.src, *cpArgs.dest, *cpArgs.resume)

	case loginCmd.FullCommand():
		login()

	case logoutCmd.FullCommand():
		logout()

	case pushCmd.FullCommand():
		{
			userVersion := *pushArgs.userVersion
			if userVersion == "" && *pushArgs.userVersionFile != "" {
				buf, err := ioutil.ReadFile(*pushArgs.userVersionFile)
				must(err)
				userVersion = strings.TrimSpace(string(buf))
				if strings.ContainsAny(userVersion, "\r\n") {
					must(fmt.Errorf("%s contains line breaks, refusing to use as userversion", *pushArgs.userVersionFile))
				}
			}
			push(*pushArgs.src, *pushArgs.target, userVersion, *pushArgs.fixPerms)
		}

	case fetchCmd.FullCommand():
		fetch(*fetchArgs.target, *fetchArgs.out)

	case statusCmd.FullCommand():
		status(*statusArgs.target)

	case untarCmd.FullCommand():
		untar(*untarArgs.file, *untarArgs.dir)

	case unzipCmd.FullCommand():
		unzip(*unzipArgs.file, *unzipArgs.dir, *unzipArgs.resumeFile)

	case wipeCmd.FullCommand():
		wipe(*wipeArgs.path)

	case mkdirCmd.FullCommand():
		mkdir(*mkdirArgs.path)

	case dittoCmd.FullCommand():
		ditto(*dittoArgs.src, *dittoArgs.dst)

	case sizeofCmd.FullCommand():
		sizeof(*sizeofArgs.path)

	case diffCmd.FullCommand():
		diff(*diffArgs.old, *diffArgs.new, *diffArgs.patch, butlerCompressionSettings())

	case applyCmd.FullCommand():
		apply(*applyArgs.patch, *applyArgs.old, *applyArgs.dir, *applyArgs.inplace, *applyArgs.signature, *applyArgs.wounds)

	case verifyCmd.FullCommand():
		verify(*verifyArgs.signature, *verifyArgs.dir, *verifyArgs.wounds, *verifyArgs.heal)

	case signCmd.FullCommand():
		sign(*signArgs.output, *signArgs.signature, butlerCompressionSettings(), *signArgs.fixPerms)

	case healCmd.FullCommand():
		heal(*healArgs.dir, *healArgs.wounds, *healArgs.spec)

	case probeCmd.FullCommand():
		probe(*probeArgs.patch)

	case bsdiffCmd.FullCommand():
		cmdBsdiff(*bsdiffArgs.target, *bsdiffArgs.source, *bsdiffArgs.patch, *bsdiffArgs.concurrency, *bsdiffArgs.measureOverhead)

	case bspatchCmd.FullCommand():
		bspatch(*bspatchArgs.patch, *bspatchArgs.target, *bspatchArgs.output)

	case whichCmd.FullCommand():
		which()

	case versionCmd.FullCommand():
		log.Println(versionString)
		os.Exit(0)

	case fileCmd.FullCommand():
		file(*fileArgs.file)

	case lsCmd.FullCommand():
		ls(*lsArgs.file)

	case upgradeCmd.FullCommand():
		upgrade(*upgradeArgs.head)

	case ugpradeCmd.FullCommand():
		upgrade(*upgradeArgs.head)

	case updateCmd.FullCommand():
		upgrade(*updateArgs.head)
	}
}