• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang cli.Context类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/AudriusButkevicius/cli.Context的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Context类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: devicesAdd

func devicesAdd(c *cli.Context) {
	nid := c.Args()[0]
	id := parseDeviceID(nid)

	newDevice := config.DeviceConfiguration{
		DeviceID:  id,
		Name:      nid,
		Addresses: []string{"dynamic"},
	}

	if len(c.Args()) > 1 {
		newDevice.Name = c.Args()[1]
	}

	if len(c.Args()) > 2 {
		addresses := c.Args()[2:]
		for _, item := range addresses {
			if item == "dynamic" {
				continue
			}
			validAddress(item)
		}
		newDevice.Addresses = addresses
	}

	cfg := getConfig(c)
	for _, device := range cfg.Devices {
		if device.DeviceID == id {
			die("Device " + nid + " already exists")
		}
	}
	cfg.Devices = append(cfg.Devices, newDevice)
	setConfig(c, cfg)
}
开发者ID:modulexcite,项目名称:syncthing-cli,代码行数:34,代码来源:cmd_devices.go


示例2: devicesGet

func devicesGet(c *cli.Context) {
	nid := c.Args()[0]
	id := parseDeviceID(nid)
	arg := c.Args()[1]
	cfg := getConfig(c)
	for _, device := range cfg.Devices {
		if device.DeviceID != id {
			continue
		}
		switch strings.ToLower(arg) {
		case "name":
			fmt.Println(device.Name)
		case "address":
			fmt.Println(strings.Join(device.Addresses, "\n"))
		case "compression":
			fmt.Println(device.Compression.String())
		case "certname":
			fmt.Println(device.CertName)
		case "introducer":
			fmt.Println(device.Introducer)
		default:
			die("Invalid property: " + arg + "\nAvailable properties: name, address, compression, certname, introducer")
		}
		return
	}
	die("Device " + nid + " not found")
}
开发者ID:modulexcite,项目名称:syncthing-cli,代码行数:27,代码来源:cmd_devices.go


示例3: guiGet

func guiGet(c *cli.Context) {
	cfg := getConfig(c).GUI
	arg := c.Args()[0]
	switch strings.ToLower(arg) {
	case "enabled":
		fmt.Println(cfg.Enabled)
	case "tls":
		fmt.Println(cfg.UseTLS)
	case "address":
		fmt.Println(cfg.Address)
	case "user":
		if cfg.User != "" {
			fmt.Println(cfg.User)
		}
	case "password":
		if cfg.User != "" {
			fmt.Println(cfg.Password)
		}
	case "apikey":
		if cfg.APIKey != "" {
			fmt.Println(cfg.APIKey)
		}
	default:
		die("Invalid setting: " + arg + "\nAvailable settings: enabled, tls, address, user, password, apikey")
	}
}
开发者ID:modulexcite,项目名称:syncthing-cli,代码行数:26,代码来源:cmd_gui.go


示例4: optionsSet

func optionsSet(c *cli.Context) {
	config := getConfig(c)
	arg := c.Args()[0]
	val := c.Args()[1]
	switch strings.ToLower(arg) {
	case "address":
		for _, item := range c.Args().Tail() {
			validAddress(item)
		}
		config.Options.ListenAddresses = c.Args().Tail()
	case "globalannenabled":
		config.Options.GlobalAnnEnabled = parseBool(val)
	case "globalannserver":
		for _, item := range c.Args().Tail() {
			validAddress(item)
		}
		config.Options.GlobalAnnServers = c.Args().Tail()
	case "localannenabled":
		config.Options.LocalAnnEnabled = parseBool(val)
	case "localannport":
		config.Options.LocalAnnPort = parsePort(val)
	case "maxsend":
		config.Options.MaxSendKbps = parseUint(val)
	case "maxrecv":
		config.Options.MaxRecvKbps = parseUint(val)
	case "reconnect":
		config.Options.ReconnectIntervalS = parseUint(val)
	case "browser":
		config.Options.StartBrowser = parseBool(val)
	case "nat":
		config.Options.NATEnabled = parseBool(val)
	case "natlease":
		config.Options.NATLeaseM = parseUint(val)
	case "natrenew":
		config.Options.NATRenewalM = parseUint(val)
	case "reporting":
		switch strings.ToLower(val) {
		case "u", "undecided", "unset":
			config.Options.URAccepted = 0
		default:
			boolvalue := parseBool(val)
			if boolvalue {
				config.Options.URAccepted = 1
			} else {
				config.Options.URAccepted = -1
			}
		}
	case "wake":
		config.Options.RestartOnWakeup = parseBool(val)
	default:
		die("Invalid setting: " + arg + "\nAvailable settings: address, globalannenabled, globalannserver, localannenabled, localannport, maxsend, maxrecv, reconnect, browser, upnp, upnplease, upnprenew, reporting, wake")
	}
	setConfig(c, config)
}
开发者ID:nrm21,项目名称:syncthing,代码行数:54,代码来源:cmd_options.go


示例5: foldersAdd

func foldersAdd(c *cli.Context) {
	cfg := getConfig(c)
	abs, err := filepath.Abs(c.Args()[1])
	die(err)
	folder := config.FolderConfiguration{
		ID:      c.Args()[0],
		RawPath: filepath.Clean(abs),
	}
	cfg.Folders = append(cfg.Folders, folder)
	setConfig(c, cfg)
}
开发者ID:modulexcite,项目名称:syncthing-cli,代码行数:11,代码来源:cmd_folders.go


示例6: errorsPush

func errorsPush(c *cli.Context) {
	err := strings.Join(c.Args(), " ")
	response := httpPost(c, "system/error", strings.TrimSpace(err))
	if response.StatusCode != 200 {
		err = fmt.Sprint("Failed to push error\nStatus code: ", response.StatusCode)
		body := string(responseToBArray(response))
		if body != "" {
			err += "\nBody: " + body
		}
		die(err)
	}
}
开发者ID:nrm21,项目名称:syncthing,代码行数:12,代码来源:cmd_errors.go


示例7: foldersDevicesClear

func foldersDevicesClear(c *cli.Context) {
	rid := c.Args()[0]
	cfg := getConfig(c)
	for i, folder := range cfg.Folders {
		if folder.ID != rid {
			continue
		}
		cfg.Folders[i].Devices = []config.FolderDeviceConfiguration{}
		setConfig(c, cfg)
		return
	}
	die("Folder " + rid + " not found")
}
开发者ID:modulexcite,项目名称:syncthing-cli,代码行数:13,代码来源:cmd_folders.go


示例8: foldersDevicesAdd

func foldersDevicesAdd(c *cli.Context) {
	rid := c.Args()[0]
	nid := parseDeviceID(c.Args()[1])
	cfg := getConfig(c)
	for i, folder := range cfg.Folders {
		if folder.ID != rid {
			continue
		}
		for _, device := range folder.Devices {
			if device.DeviceID == nid {
				die("Device " + c.Args()[1] + " is already part of this folder")
			}
		}
		for _, device := range cfg.Devices {
			if device.DeviceID == nid {
				cfg.Folders[i].Devices = append(folder.Devices, config.FolderDeviceConfiguration{
					DeviceID: device.DeviceID,
				})
				setConfig(c, cfg)
				return
			}
		}
		die("Device " + c.Args()[1] + " not found in device list")
	}
	die("Folder " + rid + " not found")
}
开发者ID:modulexcite,项目名称:syncthing-cli,代码行数:26,代码来源:cmd_folders.go


示例9: foldersUnset

func foldersUnset(c *cli.Context) {
	rid := c.Args()[0]
	arg := strings.ToLower(c.Args()[1])
	cfg := getConfig(c)
	for i, folder := range cfg.Folders {
		if folder.ID != rid {
			continue
		}
		if strings.HasPrefix(arg, "versioning-") {
			arg = arg[11:]
			if _, ok := folder.Versioning.Params[arg]; ok {
				delete(cfg.Folders[i].Versioning.Params, arg)
				setConfig(c, cfg)
				return
			}
			die("Versioning property " + c.Args()[1][11:] + " not found")
		}
		switch arg {
		case "versioning":
			cfg.Folders[i].Versioning.Type = ""
			cfg.Folders[i].Versioning.Params = make(map[string]string)
		default:
			die("Invalid property: " + c.Args()[1] + "\nAvailable properties: versioning, versioning-<key>")
		}
		setConfig(c, cfg)
		return
	}
	die("Folder " + rid + " not found")
}
开发者ID:modulexcite,项目名称:syncthing-cli,代码行数:29,代码来源:cmd_folders.go


示例10: foldersSet

func foldersSet(c *cli.Context) {
	rid := c.Args()[0]
	arg := strings.ToLower(c.Args()[1])
	val := strings.Join(c.Args()[2:], " ")
	cfg := getConfig(c)
	for i, folder := range cfg.Folders {
		if folder.ID != rid {
			continue
		}
		if strings.HasPrefix(arg, "versioning-") {
			cfg.Folders[i].Versioning.Params[arg[11:]] = val
			setConfig(c, cfg)
			return
		}
		switch arg {
		case "directory":
			cfg.Folders[i].RawPath = val
		case "master":
			cfg.Folders[i].ReadOnly = parseBool(val)
		case "permissions":
			cfg.Folders[i].IgnorePerms = parseBool(val)
		case "rescan":
			cfg.Folders[i].RescanIntervalS = parseInt(val)
		case "versioning":
			cfg.Folders[i].Versioning.Type = val
		default:
			die("Invalid property: " + c.Args()[1] + "\nAvailable properties: directory, master, permissions, versioning, versioning-<key>")
		}
		setConfig(c, cfg)
		return
	}
	die("Folder " + rid + " not found")
}
开发者ID:modulexcite,项目名称:syncthing-cli,代码行数:33,代码来源:cmd_folders.go


示例11: foldersRemove

func foldersRemove(c *cli.Context) {
	cfg := getConfig(c)
	rid := c.Args()[0]
	for i, folder := range cfg.Folders {
		if folder.ID == rid {
			last := len(cfg.Folders) - 1
			cfg.Folders[i] = cfg.Folders[last]
			cfg.Folders = cfg.Folders[:last]
			setConfig(c, cfg)
			return
		}
	}
	die("Folder " + rid + " not found")
}
开发者ID:modulexcite,项目名称:syncthing-cli,代码行数:14,代码来源:cmd_folders.go


示例12: foldersDevicesList

func foldersDevicesList(c *cli.Context) {
	rid := c.Args()[0]
	cfg := getConfig(c)
	for _, folder := range cfg.Folders {
		if folder.ID != rid {
			continue
		}
		for _, device := range folder.Devices {
			fmt.Println(device.DeviceID)
		}
		return
	}
	die("Folder " + rid + " not found")
}
开发者ID:modulexcite,项目名称:syncthing-cli,代码行数:14,代码来源:cmd_folders.go


示例13: guiUnset

func guiUnset(c *cli.Context) {
	cfg := getConfig(c)
	arg := c.Args()[0]
	switch strings.ToLower(arg) {
	case "user":
		cfg.GUI.User = ""
	case "password":
		cfg.GUI.Password = ""
	case "apikey":
		cfg.GUI.APIKey = ""
	default:
		die("Invalid setting: " + arg + "\nAvailable settings: user, password, apikey")
	}
	setConfig(c, cfg)
}
开发者ID:modulexcite,项目名称:syncthing-cli,代码行数:15,代码来源:cmd_gui.go


示例14: optionsGet

func optionsGet(c *cli.Context) {
	cfg := getConfig(c).Options
	arg := c.Args()[0]
	switch strings.ToLower(arg) {
	case "address":
		fmt.Println(strings.Join(cfg.ListenAddresses, "\n"))
	case "globalannenabled":
		fmt.Println(cfg.GlobalAnnEnabled)
	case "globalannservers":
		fmt.Println(strings.Join(cfg.GlobalAnnServers, "\n"))
	case "localannenabled":
		fmt.Println(cfg.LocalAnnEnabled)
	case "localannport":
		fmt.Println(cfg.LocalAnnPort)
	case "maxsend":
		fmt.Println(cfg.MaxSendKbps)
	case "maxrecv":
		fmt.Println(cfg.MaxRecvKbps)
	case "reconnect":
		fmt.Println(cfg.ReconnectIntervalS)
	case "browser":
		fmt.Println(cfg.StartBrowser)
	case "nat":
		fmt.Println(cfg.NATEnabled)
	case "natlease":
		fmt.Println(cfg.NATLeaseM)
	case "natrenew":
		fmt.Println(cfg.NATRenewalM)
	case "reporting":
		switch cfg.URAccepted {
		case -1:
			fmt.Println("false")
		case 0:
			fmt.Println("undecided/false")
		case 1:
			fmt.Println("true")
		default:
			fmt.Println("unknown")
		}
	case "wake":
		fmt.Println(cfg.RestartOnWakeup)
	default:
		die("Invalid setting: " + arg + "\nAvailable settings: address, globalannenabled, globalannserver, localannenabled, localannport, maxsend, maxrecv, reconnect, browser, upnp, upnplease, upnprenew, reporting, wake")
	}
}
开发者ID:nrm21,项目名称:syncthing,代码行数:45,代码来源:cmd_options.go


示例15: devicesRemove

func devicesRemove(c *cli.Context) {
	nid := c.Args()[0]
	id := parseDeviceID(nid)
	if nid == getMyID(c) {
		die("Cannot remove yourself")
	}
	cfg := getConfig(c)
	for i, device := range cfg.Devices {
		if device.DeviceID == id {
			last := len(cfg.Devices) - 1
			cfg.Devices[i] = cfg.Devices[last]
			cfg.Devices = cfg.Devices[:last]
			setConfig(c, cfg)
			return
		}
	}
	die("Device " + nid + " not found")
}
开发者ID:modulexcite,项目名称:syncthing-cli,代码行数:18,代码来源:cmd_devices.go


示例16: foldersOverride

func foldersOverride(c *cli.Context) {
	cfg := getConfig(c)
	rid := c.Args()[0]
	for _, folder := range cfg.Folders {
		if folder.ID == rid && folder.ReadOnly {
			response := httpPost(c, "db/override", "")
			if response.StatusCode != 200 {
				err := fmt.Sprint("Failed to override changes\nStatus code: ", response.StatusCode)
				body := string(responseToBArray(response))
				if body != "" {
					err += "\nBody: " + body
				}
				die(err)
			}
			return
		}
	}
	die("Folder " + rid + " not found or folder not master")
}
开发者ID:modulexcite,项目名称:syncthing-cli,代码行数:19,代码来源:cmd_folders.go


示例17: guiSet

func guiSet(c *cli.Context) {
	cfg := getConfig(c)
	arg := c.Args()[0]
	val := c.Args()[1]
	switch strings.ToLower(arg) {
	case "enabled":
		cfg.GUI.Enabled = parseBool(val)
	case "tls":
		cfg.GUI.UseTLS = parseBool(val)
	case "address":
		validAddress(val)
		cfg.GUI.Address = val
	case "user":
		cfg.GUI.User = val
	case "password":
		cfg.GUI.Password = val
	case "apikey":
		cfg.GUI.APIKey = val
	default:
		die("Invalid setting: " + arg + "\nAvailable settings: enabled, tls, address, user, password, apikey")
	}
	setConfig(c, cfg)
}
开发者ID:modulexcite,项目名称:syncthing-cli,代码行数:23,代码来源:cmd_gui.go


示例18: foldersGet

func foldersGet(c *cli.Context) {
	cfg := getConfig(c)
	rid := c.Args()[0]
	arg := strings.ToLower(c.Args()[1])
	for _, folder := range cfg.Folders {
		if folder.ID != rid {
			continue
		}
		if strings.HasPrefix(arg, "versioning-") {
			arg = arg[11:]
			value, ok := folder.Versioning.Params[arg]
			if ok {
				fmt.Println(value)
				return
			}
			die("Versioning property " + c.Args()[1][11:] + " not found")
		}
		switch arg {
		case "directory":
			fmt.Println(folder.RawPath)
		case "master":
			fmt.Println(folder.ReadOnly)
		case "permissions":
			fmt.Println(folder.IgnorePerms)
		case "rescan":
			fmt.Println(folder.RescanIntervalS)
		case "versioning":
			if folder.Versioning.Type != "" {
				fmt.Println(folder.Versioning.Type)
			}
		default:
			die("Invalid property: " + c.Args()[1] + "\nAvailable properties: directory, master, permissions, versioning, versioning-<key>")
		}
		return
	}
	die("Folder " + rid + " not found")
}
开发者ID:modulexcite,项目名称:syncthing-cli,代码行数:37,代码来源:cmd_folders.go


示例19: foldersDevicesRemove

func foldersDevicesRemove(c *cli.Context) {
	rid := c.Args()[0]
	nid := parseDeviceID(c.Args()[1])
	cfg := getConfig(c)
	for ri, folder := range cfg.Folders {
		if folder.ID != rid {
			continue
		}
		for ni, device := range folder.Devices {
			if device.DeviceID == nid {
				last := len(folder.Devices) - 1
				cfg.Folders[ri].Devices[ni] = folder.Devices[last]
				cfg.Folders[ri].Devices = cfg.Folders[ri].Devices[:last]
				setConfig(c, cfg)
				return
			}
		}
		die("Device " + c.Args()[1] + " not found")
	}
	die("Folder " + rid + " not found")
}
开发者ID:modulexcite,项目名称:syncthing-cli,代码行数:21,代码来源:cmd_folders.go


示例20: devicesSet

func devicesSet(c *cli.Context) {
	nid := c.Args()[0]
	id := parseDeviceID(nid)
	arg := c.Args()[1]
	config := getConfig(c)
	for i, device := range config.Devices {
		if device.DeviceID != id {
			continue
		}
		switch strings.ToLower(arg) {
		case "name":
			config.Devices[i].Name = strings.Join(c.Args()[2:], " ")
		case "address":
			for _, item := range c.Args()[2:] {
				if item == "dynamic" {
					continue
				}
				validAddress(item)
			}
			config.Devices[i].Addresses = c.Args()[2:]
		case "compression":
			err := config.Devices[i].Compression.UnmarshalText([]byte(c.Args()[2]))
			die(err)
		case "certname":
			config.Devices[i].CertName = strings.Join(c.Args()[2:], " ")
		case "introducer":
			config.Devices[i].Introducer = parseBool(c.Args()[2])
		default:
			die("Invalid property: " + arg + "\nAvailable properties: name, address, compression, certname, introducer")
		}
		setConfig(c, config)
		return
	}
	die("Device " + nid + " not found")
}
开发者ID:modulexcite,项目名称:syncthing-cli,代码行数:35,代码来源:cmd_devices.go



注:本文中的github.com/AudriusButkevicius/cli.Context类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang promise.Promise类代码示例发布时间:2022-05-24
下一篇:
Golang cli.App类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap