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

Golang internal.Exit函数代码示例

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

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



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

示例1: postHookRunActionOnMessage

func (ui *tatui) postHookRunActionOnMessage(action string, msg tat.Message) {
	hook := strings.TrimSpace(viper.GetString("post-hook-run-action"))
	if hook == "" {
		return
	}

	_, err := exec.LookPath(hook)
	if err != nil {
		internal.Exit("Invalid hook path for post-hook-run-action, err: %s", err.Error())
		return
	}

	jsonStr, err := json.Marshal(msg)
	if err != nil {
		internal.Exit("Error while marshalling msg for post-hook-run-action, err: %s", err.Error())
		return
	}

	cmd := exec.Command(hook, action, msg.ID, string(jsonStr))
	if e := cmd.Start(); e != nil {
		internal.Exit("Error with post-hook-run-action, err: %s", err.Error())
		return
	}

	ui.msg.Text = "Waiting " + hook + "for command to finish..."
	err = cmd.Wait()
	ui.msg.Text = fmt.Sprintf("Command finished: %v", err)
}
开发者ID:ovh,项目名称:tatcli,代码行数:28,代码来源:messages.go


示例2: doUpdate

func doUpdate(baseurl, architecture string) {
	if architecture == "" {
		text := "You seem to have a custom build of tatcli.\n"
		text += "Please download latest release on %s\n"
		internal.Exit(text, urlGitubReleases)
	}

	url := getURLArtifactFromGithub(architecture)
	if internal.Debug {
		fmt.Printf("Url to update tatcli: %s\n", url)
	}

	resp, err := http.Get(url)
	if err != nil {
		internal.Exit("Error when downloading tatcli from url: %s, err:%s\n", url, err.Error())
	}

	if contentType := getContentType(resp); contentType != "application/octet-stream" {
		fmt.Printf("Url: %s\n", url)
		internal.Exit("Invalid Binary (Content-Type: %s). Please try again or download it manually from %s\n", contentType, urlGitubReleases)
	}

	if resp.StatusCode != 200 {
		internal.Exit("Error http code: %d, url called: %s\n", resp.StatusCode, url)
	}

	fmt.Printf("Getting latest release from : %s ...\n", url)
	defer resp.Body.Close()
	if err = update.Apply(resp.Body, update.Options{}); err != nil {
		internal.Exit("Error when updating tatcli from url: %s err:%s\n", url, err.Error())
	}
	fmt.Println("Update done.")
}
开发者ID:ovh,项目名称:tatcli,代码行数:33,代码来源:update.go


示例3: loadArgs

// loadArgs load args form command line and return topic, filter, command
func (ui *tatui) loadArgs(args []string) []string {
	// example :
	// /YourTopic/SubTopic /split label:open label:doing label:done /save
	// /YourTopic/SubTopic /run CD
	// /YourTopic/SubTopic /run CD /save
	// /YourTopic/SubTopic /monitoring /save
	if len(args) < 1 {
		return []string{}
	}

	topicName := ""
	if strings.HasPrefix(args[0], "/") {
		topicName = args[0]
	}
	c := &tat.TopicCriteria{Topic: strings.TrimSpace(topicName)}

	//topicsB, err := internal.Request("GET", 200, topic.TopicsListURL(c), nil)
	topicsJSON, err := internal.Client().TopicList(c)
	if err != nil {
		internal.Exit("Error while loading topic %s error:%s", args[0], err.Error())
	}

	if len(topicsJSON.Topics) != 1 {
		internal.Exit("Args on tatcli ui should begin with topic name. Please check it on %s", args[0])
	}

	ui.currentTopic = topicsJSON.Topics[0]

	commands := []string{}
	cmd := ""
	for i := 1; i < len(args); i++ {
		if strings.HasPrefix(args[i], "/") {
			if cmd != "" {
				commands = append(commands, cmd)
			}
			cmd = args[i]
		} else {
			cmd += " " + args[i]
		}
	}
	if cmd != "" {
		commands = append(commands, cmd)
	}
	return commands
}
开发者ID:ovh,项目名称:tatcli,代码行数:46,代码来源:ui.go


示例4: getURLArtifactFromGithub

func getURLArtifactFromGithub(architecture string) string {
	client := github.NewClient(nil)
	release, resp, err := client.Repositories.GetLatestRelease("ovh", "tatcli")
	if err != nil {
		internal.Exit("Repositories.GetLatestRelease returned error: %v\n%v", err, resp.Body)
	}

	if len(release.Assets) > 0 {
		for _, asset := range release.Assets {
			if *asset.Name == "tatcli-"+architecture {
				return *asset.BrowserDownloadURL
			}
		}
	}

	text := "Invalid Artifacts on latest release. Please try again in few minutes.\n"
	text += "If the problem persists, please open an issue on https://github.com/ovh/tatcli/issues\n"
	internal.Exit(text)
	return ""
}
开发者ID:ovh,项目名称:tatcli,代码行数:20,代码来源:update.go


示例5: loadConfig

func (ui *tatui) loadConfig() {
	internal.ReadConfig()
	filters := viper.GetStringSlice("filters")

	// no range to keep order
	for index := 0; index < len(filters); index++ {
		filter := filters[index]
		tuples := strings.Split(filter, " ")
		if len(tuples) <= 2 {
			continue
		}
		topic := tuples[1]
		if _, ok := ui.currentFilterMessages[topic]; !ok {
			ui.currentFilterMessages[topic] = make(map[int]*tat.MessageCriteria)
			ui.currentFilterMessagesText[topic] = make(map[int]string)
		}
		c, criteriaText := ui.prepareFilterMessages(strings.Join(tuples[2:], " "), tuples[0], topic)
		ui.currentFilterMessages[topic][len(ui.currentFilterMessages[topic])] = c
		ui.currentFilterMessagesText[topic][len(ui.currentFilterMessagesText[topic])] = criteriaText
	}

	commands := viper.GetStringSlice("commands")
	// no range to keep order
	for index := 0; index < len(commands); index++ {
		commandsOnTopic := commands[index]
		tuples := strings.Split(strings.TrimSpace(commandsOnTopic), " ")
		if len(tuples) <= 1 {
			continue
		}
		topic := tuples[0]
		ui.uiTopicCommands[topic] = commandsOnTopic[len(topic):]
	}

	var conf config.TemplateJSONType
	err := viper.Unmarshal(&conf)
	if err != nil {
		internal.Exit("unable to decode confif file, err: %v", err)
	}

	ui.hooks = conf.Hooks
}
开发者ID:ovh,项目名称:tatcli,代码行数:41,代码来源:config.go


示例6:

package stats

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdStatsDBCollections = &cobra.Command{
	Use:   "dbCollections",
	Short: "DB Stats on each collection: tatcli stats dbCollections",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) >= 1 {
			internal.Exit("Invalid argument: tatcli stats dbCollections --help\n")
			cmd.Usage()
		} else {
			out, err := internal.Client().StatsDBCollections()
			internal.Check(err)
			internal.Print(out)
		}
	},
}
开发者ID:ovh,项目名称:tatcli,代码行数:21,代码来源:db_collections.go


示例7: init

package topic

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

func init() {
	cmdTopicDeleteParameter.Flags().BoolVarP(&recursive, "recursive", "r", false, "Remove Parameter recursively")
}

var cmdTopicDeleteParameter = &cobra.Command{
	Use:   "deleteParameter",
	Short: "Remove Parameter to a topic: tatcli topic deleteParameter [--recursive] <topic> <key> [<key2>]... ",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) >= 2 {
			err := internal.Client().TopicDeleteParameters(args[0], args[1:], recursive)
			internal.Check(err)
		} else {
			internal.Exit("Invalid argument: tatcli topic deleteParameter --help\n")
		}
	},
}
开发者ID:ovh,项目名称:tatcli,代码行数:23,代码来源:delete_parameter.go


示例8:

package user

import (
	"github.com/ovh/tat"
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdUserSetAdmin = &cobra.Command{
	Use:   "setAdmin",
	Short: "Grant user to Tat admin (admin only): tatcli user setAdmin <username>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 1 {
			out, err := internal.Client().UserSetAdmin(tat.UsernameUserJSON{
				Username: args[0],
			})
			internal.Check(err)
			internal.Print(out)
		} else {
			internal.Exit("Invalid argument: tatcli user setAdmin --help\n")
		}
	},
}
开发者ID:ovh,项目名称:tatcli,代码行数:23,代码来源:set_admin.go


示例9:

package message

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdMessageVoteDown = &cobra.Command{
	Use:   "votedown",
	Short: "Vote Down a message: tatcli message votedown <topic> <idMessage>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 1 {
			out, err := internal.Client().MessageVoteDown(args[0], args[1])
			internal.Check(err)
			if internal.Verbose {
				internal.Print(out)
			}
		} else {
			internal.Exit("Invalid argument to votedown a message: tatcli message votedown --help\n")
		}
	},
}
开发者ID:ovh,项目名称:tatcli,代码行数:22,代码来源:votedown.go


示例10:

package user

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdUserDisableNotificationsTopic = &cobra.Command{
	Use:   "disableNotificationsTopic",
	Short: "Disable notifications on a topic: tatcli user disableNotificationsTopic <topicName>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 1 {
			out, err := internal.Client().UserDisableNotificationsTopic(args[0])
			internal.Check(err)
			internal.Print(out)
		} else {
			internal.Exit("Invalid argument: tatcli user disableNotificationsTopic --help\n")
		}
	},
}
开发者ID:ovh,项目名称:tatcli,代码行数:20,代码来源:disable_notifications_topic.go


示例11: init

var versionNewLine bool

func init() {
	Cmd.Flags().BoolVarP(&versionNewLine, "versionNewLine", "", true, "New line after version number. If true, display Version Engine too")
}

// Cmd version
var Cmd = &cobra.Command{
	Use:     "version",
	Short:   "Display Version of tatcli and tat engine if configured: tatcli version",
	Long:    `tatcli version`,
	Aliases: []string{"v"},
	Run: func(cmd *cobra.Command, args []string) {
		if versionNewLine {
			fmt.Printf("Version tatcli: %s\n", internal.VERSION)

			internal.ReadConfig()
			if viper.GetString("url") == "" {
				internal.Exit("Version Engine: No Engine Configured. See tatcli config --help\n")
			} else {
				out, err := internal.Client().Version()
				internal.Check(err)
				internal.Print(out)
			}
		} else {
			fmt.Print(internal.VERSION)
		}
	},
}
开发者ID:ovh,项目名称:tatcli,代码行数:29,代码来源:version.go


示例12:

package group

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdGroupDeleteUser = &cobra.Command{
	Use:   "deleteUser",
	Short: "Delete Users from a group: tacli group deleteUser <groupname> <username1> [<username2> ... ]",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) >= 2 {
			err := internal.Client().GroupDeleteUsers(args[0], args[1:])
			internal.Check(err)
		} else {
			internal.Exit("Invalid argument: tatcli group deleteUser --help\n")
		}
	},
}
开发者ID:ovh,项目名称:tatcli,代码行数:19,代码来源:delete_user.go


示例13:

package message

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdMessageLike = &cobra.Command{
	Use:   "like",
	Short: "Like a message: tatcli message like <topic> <idMessage>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 2 {
			out, err := internal.Client().MessageLike(args[0], args[1])
			internal.Check(err)
			if internal.Verbose {
				internal.Print(out)
			}
		} else {
			internal.Exit("Invalid argument to like a message: tatcli message like --help\n")
		}
	},
}
开发者ID:ovh,项目名称:tatcli,代码行数:22,代码来源:like.go


示例14:

package topic

import (
	"github.com/ovh/tat"
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdTopicTruncateLabels = &cobra.Command{
	Use:   "truncatelabels",
	Short: "Truncate Labels on this topic, only for tat admin and administrators on topic : tatcli topic truncatelabels <topic>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 1 {
			out, err := internal.Client().TopicTruncateLabels(tat.TopicNameJSON{Topic: args[0]})
			internal.Check(err)
			if internal.Verbose {
				internal.Print(out)
			}
		} else {
			internal.Exit("Invalid argument: tatcli topic truncatelabels --help\n")
		}
	},
}
开发者ID:ovh,项目名称:tatcli,代码行数:23,代码来源:truncate_labels.go


示例15:

package message

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdMessageMove = &cobra.Command{
	Use:   "move",
	Short: "Move a message: tatcli message move <oldTopic> <idMessage> <newTopic>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 3 {
			out, err := internal.Client().MessageMove(args[0], args[1], args[2])
			internal.Check(err)
			if internal.Verbose {
				internal.Print(out)
			}
		} else {
			internal.Exit("Invalid argument to move a message: tatcli message move --help\n")
		}
	},
}
开发者ID:ovh,项目名称:tatcli,代码行数:22,代码来源:move.go


示例16:

package topic

import (
	"strings"

	"github.com/ovh/tat"
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdTopicCreate = &cobra.Command{
	Use:   "create",
	Short: "Create a new topic: tatcli create <topic> <description of topic>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) >= 2 {
			description := strings.Join(args[1:], " ")
			topic, err := internal.Client().TopicCreate(tat.TopicCreateJSON{
				Topic:       args[0],
				Description: description,
			})
			internal.Check(err)
			if internal.Verbose {
				internal.Print(topic)
			}
		} else {
			internal.Exit("Invalid argument: tatcli topic create --help\n")
		}
	},
}
开发者ID:ovh,项目名称:tatcli,代码行数:29,代码来源:create.go


示例17:

package user

import (
	"strings"

	"github.com/ovh/tat"
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdUserAdd = &cobra.Command{
	Use:   "add",
	Short: "Add a user: tatcli user add <username> <email> <fullname>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) >= 3 {
			out, err := internal.Client().UserAdd(tat.UserCreateJSON{
				Username: args[0],
				Fullname: strings.Join(args[2:], " "),
				Email:    args[1],
				Callback: "tatcli --url=:scheme://:host::port:path user verify --save :username :token",
			})
			internal.Check(err)
			internal.Print(out)
		} else {
			internal.Exit("Invalid argument to add user: tatcli user add --help\n")
		}
	},
}
开发者ID:ovh,项目名称:tatcli,代码行数:28,代码来源:add.go


示例18:

package presence

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdPresenceDelete = &cobra.Command{
	Use:   "delete",
	Short: "Delete a user's presence on one topic: tatcli presence delete <topic> <username>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 2 {
			err := internal.Client().PresenceDelete(args[0], args[1])
			internal.Check(err)
		} else {
			internal.Exit("Invalid argument: tatcli presence delete --help\n")
		}
	},
}
开发者ID:ovh,项目名称:tatcli,代码行数:19,代码来源:delete.go


示例19: initHandles


//.........这里部分代码省略.........
		switch ui.selectedPane {
		case uiTopics:
			ui.enterTopic()
			return
		case uiMessages:
			ui.enterMessage()
			return
		case uiActionBox:
			ui.processMsg()
			ui.render()
		}
	})

	termui.Handle("/sys/kbd/<space>", func(e termui.Event) {
		if ui.isOnActionBox() {
			ui.send.Text += " "
		}
		ui.render()
	})

	termui.Handle("/sys/kbd/<tab>", func(e termui.Event) {
		if ui.isOnActionBox() && len(ui.send.Text) > 0 && !strings.HasSuffix(ui.send.Text, " ") {
			ui.autocomplete()
		} else {
			ui.switchBox()
		}
	})

	termui.Handle("/sys/kbd/C-8", func(e termui.Event) {
		if !ui.isOnActionBox() {
			return
		}
		if len(ui.send.Text) > 0 {
			ui.send.Text = ui.send.Text[:len(ui.send.Text)-1]
			ui.render()
		}
	})

	termui.Handle("/sys/kbd/C-k", func(e termui.Event) {
		if ui.currentModeOnTopic[ui.currentTopic.Topic] == "/run" {
			ui.runActionOnMessage(true)
		} else if ui.currentModeOnTopic[ui.currentTopic.Topic] == "/monitoring" {
			ui.monitoringActionOnMessage()
		}
	})

	termui.Handle("/sys/kbd/C-j", func(e termui.Event) {
		if ui.currentModeOnTopic[ui.currentTopic.Topic] == "/run" {
			ui.runActionOnMessage(false)
		} else if ui.currentModeOnTopic[ui.currentTopic.Topic] == "/monitoring" {
			ui.monitoringActionOnMessage()
		}
	})

	termui.Handle("/sys/kbd/C-p", func(e termui.Event) {
		if _, ok := ui.uilists[uiMessages][ui.selectedPaneMessages]; ok {
			ui.openLinksInBrowser()
		}
	})

	termui.Handle("/sys/kbd/C-t", func(e termui.Event) {
		ui.toggleTopMenu(false)
	})

	termui.Handle("/sys/kbd/C-y", func(e termui.Event) {
		ui.toggleActionBox(false)
	})

	termui.Handle("/sys/kbd/C-o", func(e termui.Event) {
		if _, ok := ui.uilists[uiMessages][ui.selectedPaneMessages]; ok {
			ui.openInTatwebui()
		}
	})

	termui.Handle("/sys/kbd", func(e termui.Event) {
		if !ui.isOnActionBox() {
			ui.switchToActionBox()
		}
		ui.send.BorderFg = termui.ColorRed
		if _, ok := ui.uilists[uiActionBox][0]; ok {
			ui.uilists[uiActionBox][0].list.BorderFg = termui.ColorWhite
		}
		char := e.Data.(termui.EvtKbd).KeyStr
		ui.send.Text += char
		ui.render()
	})

	for _, h := range ui.hooks {
		if h.Shortcut == "" {
			continue
		}
		if _, ok := termui.DefaultEvtStream.Handlers["/sys/kbd/"+h.Shortcut]; ok {
			internal.Exit("Shortcut %s is already used in tatcli", h.Shortcut)
		}
		termui.Handle("/sys/kbd/"+h.Shortcut, func(e termui.Event) {
			ui.RunExec(nil, e.Path, "")
		})
	}

}
开发者ID:ovh,项目名称:tatcli,代码行数:101,代码来源:events.go


示例20:

package user

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdUserRemoveFavoriteTopic = &cobra.Command{
	Use:   "removeFavoriteTopic",
	Short: "Remove a favorite Topic: tatcli user removeFavoriteTopic <topicName>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 1 {
			out, err := internal.Client().UserRemoveFavoriteTopic(args[0])
			internal.Check(err)
			internal.Print(out)
		} else {
			internal.Exit("Invalid argument: tatcli user removeFavoriteTopic --help\n")
		}
	},
}
开发者ID:ovh,项目名称:tatcli,代码行数:20,代码来源:remove_favorite_topic.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang internal.Print函数代码示例发布时间:2022-05-28
下一篇:
Golang internal.Client函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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