本文整理汇总了Golang中github.com/lxc/lxd/shared/gnuflag.Bool函数的典型用法代码示例。如果您正苦于以下问题:Golang Bool函数的具体用法?Golang Bool怎么用?Golang Bool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Bool函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: init
"math/rand"
"os"
"os/exec"
"os/signal"
"runtime/pprof"
"sync"
"syscall"
"time"
"github.com/lxc/lxd"
"github.com/lxc/lxd/shared"
"github.com/lxc/lxd/shared/gnuflag"
)
var cpuProfile = gnuflag.String("cpuprofile", "", "Enable cpu profiling into the specified file.")
var debug = gnuflag.Bool("debug", false, "Enables debug mode.")
var group = gnuflag.String("group", "", "Group which owns the shared socket.")
var help = gnuflag.Bool("help", false, "Print this help message.")
var logfile = gnuflag.String("logfile", "", "Logfile to log to (e.g., /var/log/lxd/lxd.log).")
var memProfile = gnuflag.String("memprofile", "", "Enable memory profiling into the specified file.")
var printGoroutines = gnuflag.Int("print-goroutines-every", -1, "For debugging, print a complete stack trace every n seconds")
var syslogFlag = gnuflag.Bool("syslog", false, "Enables syslog logging.")
var verbose = gnuflag.Bool("verbose", false, "Enables verbose mode.")
var version = gnuflag.Bool("version", false, "Print LXD's version number and exit.")
func init() {
myGroup, err := shared.GroupName(os.Getgid())
if err != nil {
shared.Debugf("Problem finding default group %s", err)
}
*group = myGroup
示例2: run
func run() error {
gettext.BindTextdomain("lxd", "", nil)
gettext.Textdomain("lxd")
verbose := gnuflag.Bool("verbose", false, gettext.Gettext("Enables verbose mode."))
debug := gnuflag.Bool("debug", false, gettext.Gettext("Enables debug mode."))
forceLocal := gnuflag.Bool("force-local", false, gettext.Gettext("Enables debug mode."))
gnuflag.StringVar(&lxd.ConfigDir, "config", lxd.ConfigDir, gettext.Gettext("Alternate config directory."))
if len(os.Args) >= 3 && os.Args[1] == "config" && os.Args[2] == "profile" {
fmt.Fprintf(os.Stderr, "`lxc config profile` is deprecated, please use `lxc profile`\n")
os.Args = append(os.Args[:1], os.Args[2:]...)
}
if len(os.Args) >= 2 && (os.Args[1] == "-h" || os.Args[1] == "--help") {
os.Args[1] = "help"
}
if len(os.Args) >= 2 && (os.Args[1] == "--all") {
os.Args[1] = "help"
os.Args = append(os.Args, "--all")
}
if len(os.Args) == 2 && os.Args[1] == "--version" {
os.Args[1] = "version"
}
if len(os.Args) < 2 {
commands["help"].run(nil, nil)
os.Exit(1)
}
name := os.Args[1]
cmd, ok := commands[name]
if !ok {
fmt.Fprintf(os.Stderr, gettext.Gettext("error: unknown command: %s\n"), name)
commands["help"].run(nil, nil)
os.Exit(1)
}
cmd.flags()
gnuflag.Usage = func() {
fmt.Fprintf(os.Stderr, gettext.Gettext("Usage: %s\n\nOptions:\n\n"), strings.TrimSpace(cmd.usage()))
gnuflag.PrintDefaults()
}
os.Args = os.Args[1:]
gnuflag.Parse(true)
shared.SetLogger("", "", *verbose, *debug)
var config *lxd.Config
var err error
if *forceLocal {
config = &lxd.DefaultConfig
} else {
config, err = lxd.LoadConfig()
if err != nil {
return err
}
}
certf := lxd.ConfigPath("client.crt")
keyf := lxd.ConfigPath("client.key")
if !*forceLocal && os.Args[0] != "help" && os.Args[0] != "version" && (!shared.PathExists(certf) || !shared.PathExists(keyf)) {
fmt.Fprintf(os.Stderr, gettext.Gettext("Generating a client certificate. This may take a minute...\n"))
err = shared.FindOrGenCert(certf, keyf)
if err != nil {
return err
}
fmt.Fprintf(os.Stderr, gettext.Gettext("If this is your first run, you will need to import images using the 'lxd-images' script.\n"))
fmt.Fprintf(os.Stderr, gettext.Gettext("For example: 'lxd-images import ubuntu --alias ubuntu'.\n"))
}
err = cmd.run(config, gnuflag.Args())
if err == errArgs {
fmt.Fprintf(os.Stderr, gettext.Gettext("error: %v\n%s"), err, cmd.usage())
os.Exit(1)
}
return err
}
示例3: main
"fmt"
"io/ioutil"
"os"
"strings"
"sync"
"time"
"github.com/lxc/lxd"
"github.com/lxc/lxd/shared"
"github.com/lxc/lxd/shared/gnuflag"
)
var argCount = gnuflag.Int("count", 100, "Number of containers to create")
var argParallel = gnuflag.Int("parallel", -1, "Number of threads to use")
var argImage = gnuflag.String("image", "ubuntu:", "Image to use for the test")
var argPrivileged = gnuflag.Bool("privileged", false, "Use privileged containers")
var argFreeze = gnuflag.Bool("freeze", false, "Freeze the container right after start")
func main() {
err := run(os.Args)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(1)
}
os.Exit(0)
}
func run(args []string) error {
// Parse command line
gnuflag.Parse(true)
示例4: run
func run() error {
verbose := gnuflag.Bool("verbose", false, i18n.G("Enables verbose mode."))
debug := gnuflag.Bool("debug", false, i18n.G("Enables debug mode."))
forceLocal := gnuflag.Bool("force-local", false, i18n.G("Force using the local unix socket."))
noAlias := gnuflag.Bool("no-alias", false, i18n.G("Ignore aliases when determining what command to run."))
configDir := "$HOME/.config/lxc"
if os.Getenv("LXD_CONF") != "" {
configDir = os.Getenv("LXD_CONF")
}
configPath = os.ExpandEnv(path.Join(configDir, "config.yml"))
if len(os.Args) >= 3 && os.Args[1] == "config" && os.Args[2] == "profile" {
fmt.Fprintf(os.Stderr, i18n.G("`lxc config profile` is deprecated, please use `lxc profile`")+"\n")
os.Args = append(os.Args[:1], os.Args[2:]...)
}
if len(os.Args) >= 2 && (os.Args[1] == "-h" || os.Args[1] == "--help") {
os.Args[1] = "help"
}
if len(os.Args) >= 2 && (os.Args[1] == "--all") {
os.Args[1] = "help"
os.Args = append(os.Args, "--all")
}
if len(os.Args) == 2 && os.Args[1] == "--version" {
os.Args[1] = "version"
}
if len(os.Args) < 2 {
commands["help"].run(nil, nil)
os.Exit(1)
}
var config *lxd.Config
var err error
if *forceLocal {
config = &lxd.DefaultConfig
} else {
config, err = lxd.LoadConfig(configPath)
if err != nil {
return err
}
}
// This is quite impolite, but it seems gnuflag needs us to shift our
// own exename out of the arguments before parsing them. However, this
// is useful for execIfAlias, which wants to know exactly the command
// line we received, and in some cases is called before this shift, and
// in others after. So, let's save the original args.
origArgs := os.Args
name := os.Args[1]
/* at this point we haven't parsed the args, so we have to look for
* --no-alias by hand.
*/
if !shared.StringInSlice("--no-alias", origArgs) {
execIfAliases(config, origArgs)
}
cmd, ok := commands[name]
if !ok {
commands["help"].run(nil, nil)
fmt.Fprintf(os.Stderr, "\n"+i18n.G("error: unknown command: %s")+"\n", name)
os.Exit(1)
}
cmd.flags()
gnuflag.Usage = func() {
fmt.Fprintf(os.Stderr, i18n.G("Usage: %s")+"\n\n"+i18n.G("Options:")+"\n\n", strings.TrimSpace(cmd.usage()))
gnuflag.PrintDefaults()
}
os.Args = os.Args[1:]
gnuflag.Parse(true)
shared.Log, err = logging.GetLogger("", "", *verbose, *debug, nil)
if err != nil {
return err
}
certf := config.ConfigPath("client.crt")
keyf := config.ConfigPath("client.key")
if !*forceLocal && os.Args[0] != "help" && os.Args[0] != "version" && (!shared.PathExists(certf) || !shared.PathExists(keyf)) {
fmt.Fprintf(os.Stderr, i18n.G("Generating a client certificate. This may take a minute...")+"\n")
err = shared.FindOrGenCert(certf, keyf)
if err != nil {
return err
}
}
err = cmd.run(config, gnuflag.Args())
if err == errArgs {
/* If we got an error about invalid arguments, let's try to
* expand this as an alias
*/
if !*noAlias {
execIfAliases(config, origArgs)
//.........这里部分代码省略.........
示例5:
"strconv"
"strings"
"sync"
"syscall"
"time"
"golang.org/x/crypto/ssh/terminal"
"github.com/lxc/lxd"
"github.com/lxc/lxd/shared"
"github.com/lxc/lxd/shared/gnuflag"
"github.com/lxc/lxd/shared/logging"
)
// Global arguments
var argAuto = gnuflag.Bool("auto", false, "")
var argCPUProfile = gnuflag.String("cpuprofile", "", "")
var argDebug = gnuflag.Bool("debug", false, "")
var argGroup = gnuflag.String("group", "", "")
var argHelp = gnuflag.Bool("help", false, "")
var argLogfile = gnuflag.String("logfile", "", "")
var argMemProfile = gnuflag.String("memprofile", "", "")
var argNetworkAddress = gnuflag.String("network-address", "", "")
var argNetworkPort = gnuflag.Int("network-port", -1, "")
var argPrintGoroutinesEvery = gnuflag.Int("print-goroutines-every", -1, "")
var argStorageBackend = gnuflag.String("storage-backend", "", "")
var argStorageCreateDevice = gnuflag.String("storage-create-device", "", "")
var argStorageCreateLoop = gnuflag.Int("storage-create-loop", -1, "")
var argStoragePool = gnuflag.String("storage-pool", "", "")
var argSyslog = gnuflag.Bool("syslog", false, "")
var argTimeout = gnuflag.Int("timeout", -1, "")
示例6: run
func run() error {
verbose := gnuflag.Bool("verbose", false, i18n.G("Enables verbose mode."))
debug := gnuflag.Bool("debug", false, i18n.G("Enables debug mode."))
forceLocal := gnuflag.Bool("force-local", false, i18n.G("Force using the local unix socket."))
noAlias := gnuflag.Bool("no-alias", false, i18n.G("Ignore aliases when determining what command to run."))
configDir := "$HOME/.config/lxc"
if os.Getenv("LXD_CONF") != "" {
configDir = os.Getenv("LXD_CONF")
}
configPath = os.ExpandEnv(path.Join(configDir, "config.yml"))
if len(os.Args) >= 3 && os.Args[1] == "config" && os.Args[2] == "profile" {
fmt.Fprintf(os.Stderr, i18n.G("`lxc config profile` is deprecated, please use `lxc profile`")+"\n")
os.Args = append(os.Args[:1], os.Args[2:]...)
}
if len(os.Args) >= 2 && (os.Args[1] == "-h" || os.Args[1] == "--help") {
os.Args[1] = "help"
}
if len(os.Args) >= 2 && (os.Args[1] == "--all") {
os.Args[1] = "help"
os.Args = append(os.Args, "--all")
}
if len(os.Args) == 2 && os.Args[1] == "--version" {
os.Args[1] = "version"
}
if len(os.Args) == 2 && os.Args[1] == "--man" {
os.Args[1] = "manpage"
}
if len(os.Args) < 2 {
commands["help"].run(nil, nil)
os.Exit(1)
}
var config *lxd.Config
var err error
if *forceLocal {
config = &lxd.DefaultConfig
} else {
config, err = lxd.LoadConfig(configPath)
if err != nil {
return err
}
}
// This is quite impolite, but it seems gnuflag needs us to shift our
// own exename out of the arguments before parsing them. However, this
// is useful for execIfAlias, which wants to know exactly the command
// line we received, and in some cases is called before this shift, and
// in others after. So, let's save the original args.
origArgs := os.Args
name := os.Args[1]
/* at this point we haven't parsed the args, so we have to look for
* --no-alias by hand.
*/
if !shared.StringInSlice("--no-alias", origArgs) {
execIfAliases(config, origArgs)
}
cmd, ok := commands[name]
if !ok {
commands["help"].run(nil, nil)
fmt.Fprintf(os.Stderr, "\n"+i18n.G("error: unknown command: %s")+"\n", name)
os.Exit(1)
}
cmd.flags()
gnuflag.Usage = func() {
fmt.Fprintf(os.Stderr, i18n.G("Usage: %s")+"\n\n"+i18n.G("Options:")+"\n\n", strings.TrimSpace(cmd.usage()))
gnuflag.PrintDefaults()
}
os.Args = os.Args[1:]
gnuflag.Parse(true)
shared.Log, err = logging.GetLogger("", "", *verbose, *debug, nil)
if err != nil {
return err
}
// If the user is running a command that may attempt to connect to the local daemon
// and this is the first time the client has been run by the user, then check to see
// if LXD has been properly configured. Don't display the message if the var path
// does not exist (LXD not installed), as the user may be targeting a remote daemon.
if os.Args[0] != "help" && os.Args[0] != "version" && shared.PathExists(shared.VarPath("")) && !shared.PathExists(config.ConfigDir) {
// Create the config dir so that we don't get in here again for this user.
err = os.MkdirAll(config.ConfigDir, 0750)
if err != nil {
return err
}
fmt.Fprintf(os.Stderr, i18n.G("If this is your first time using LXD, you should also run: sudo lxd init")+"\n")
fmt.Fprintf(os.Stderr, i18n.G("To start your first container, try: lxc launch ubuntu:16.04")+"\n\n")
}
//.........这里部分代码省略.........
示例7: run
func run() error {
verbose := gnuflag.Bool("verbose", false, i18n.G("Enables verbose mode."))
debug := gnuflag.Bool("debug", false, i18n.G("Enables debug mode."))
forceLocal := gnuflag.Bool("force-local", false, i18n.G("Force using the local unix socket."))
configDir := os.Getenv("LXD_CONF")
if configDir != "" {
lxd.ConfigDir = configDir
}
if len(os.Args) >= 3 && os.Args[1] == "config" && os.Args[2] == "profile" {
fmt.Fprintf(os.Stderr, i18n.G("`lxc config profile` is deprecated, please use `lxc profile`")+"\n")
os.Args = append(os.Args[:1], os.Args[2:]...)
}
if len(os.Args) >= 2 && (os.Args[1] == "-h" || os.Args[1] == "--help") {
os.Args[1] = "help"
}
if len(os.Args) >= 2 && (os.Args[1] == "--all") {
os.Args[1] = "help"
os.Args = append(os.Args, "--all")
}
if len(os.Args) == 2 && os.Args[1] == "--version" {
os.Args[1] = "version"
}
if len(os.Args) < 2 {
commands["help"].run(nil, nil)
os.Exit(1)
}
var config *lxd.Config
var err error
if *forceLocal {
config = &lxd.DefaultConfig
} else {
config, err = lxd.LoadConfig()
if err != nil {
return err
}
// One time migration from old config
if config.DefaultRemote == "" {
_, ok := config.Remotes["local"]
if !ok {
config.Remotes["local"] = lxd.LocalRemote
}
config.DefaultRemote = "local"
lxd.SaveConfig(config)
}
}
// This is quite impolite, but it seems gnuflag needs us to shift our
// own exename out of the arguments before parsing them. However, this
// is useful for execIfAlias, which wants to know exactly the command
// line we received, and in some cases is called before this shift, and
// in others after. So, let's save the original args.
origArgs := os.Args
name := os.Args[1]
cmd, ok := commands[name]
if !ok {
execIfAliases(config, origArgs)
fmt.Fprintf(os.Stderr, i18n.G("error: unknown command: %s")+"\n", name)
commands["help"].run(nil, nil)
os.Exit(1)
}
cmd.flags()
gnuflag.Usage = func() {
fmt.Fprintf(os.Stderr, i18n.G("Usage: %s")+"\n\n"+i18n.G("Options:")+"\n\n", strings.TrimSpace(cmd.usage()))
gnuflag.PrintDefaults()
}
os.Args = os.Args[1:]
gnuflag.Parse(true)
shared.SetLogger("", "", *verbose, *debug, nil)
certf := lxd.ConfigPath("client.crt")
keyf := lxd.ConfigPath("client.key")
if !*forceLocal && os.Args[0] != "help" && os.Args[0] != "version" && (!shared.PathExists(certf) || !shared.PathExists(keyf)) {
fmt.Fprintf(os.Stderr, i18n.G("Generating a client certificate. This may take a minute...")+"\n")
err = shared.FindOrGenCert(certf, keyf)
if err != nil {
return err
}
fmt.Fprintf(os.Stderr, i18n.G("If this is your first run, you will need to import images using the 'lxd-images' script.")+"\n")
fmt.Fprintf(os.Stderr, i18n.G("For example: 'lxd-images import ubuntu --alias ubuntu'.")+"\n")
}
err = cmd.run(config, gnuflag.Args())
if err == errArgs {
/* If we got an error about invalid arguments, let's try to
* expand this as an alias
*/
//.........这里部分代码省略.........