File: flags.go

package info (click to toggle)
mirrorbits 0.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 984 kB
  • sloc: sh: 675; makefile: 93
file content (48 lines) | stat: -rw-r--r-- 1,347 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) 2014-2019 Ludovic Fauvet
// Licensed under the MIT license

package core

import (
	"flag"
	"os"
)

var (
	Daemon      bool
	Debug       bool
	Monitor     bool
	ConfigFile  string
	CpuProfile  string
	PidFile     string
	RunLog      string
	RPCPort     uint
	RPCHost     string
	RPCPassword string
	RPCAskPass  bool
	NArg        int
)

func Parseflags() {
	flag.BoolVar(&Debug, "debug", false, "Debug mode")
	flag.StringVar(&CpuProfile, "cpuprofile", "", "write cpu profile to file")
	flag.UintVar(&RPCPort, "p", 3390, "Server port")
	flag.StringVar(&RPCHost, "h", "localhost", "Server host")
	flag.StringVar(&RPCPassword, "P", "", "Server password")
	flag.BoolVar(&RPCAskPass, "a", false, "Ask for server password")
	flag.Parse()
	NArg = flag.NArg()

	daemon := flag.NewFlagSet("daemon", flag.ExitOnError)
	daemon.BoolVar(&Debug, "debug", false, "Debug mode")
	daemon.StringVar(&CpuProfile, "cpuprofile", "", "write cpu profile to file")
	daemon.StringVar(&ConfigFile, "config", "", "Path to the config file")
	daemon.BoolVar(&Monitor, "monitor", true, "Enable the background mirrors monitor")
	daemon.StringVar(&PidFile, "p", "", "Path to pid file")
	daemon.StringVar(&RunLog, "log", "", "File to output logs (default: stderr)")

	if len(os.Args) > 1 && os.Args[1] == "daemon" {
		Daemon = true
		daemon.Parse(os.Args[2:])
	}
}