当前位置: 首页>>代码示例>>Golang>>正文


Golang internal.Exit函数代码示例

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


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


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