示例#1
0
文件: truncate.go 项目: ovh/tatcli
func topicTruncate(topic string) {
	j := tat.TopicNameJSON{Topic: topic}
	if force {
		out, err := internal.Client().TopicTruncate(j)
		internal.Check(err)
		if internal.Verbose {
			internal.Print(out)
		}
	} else {
		fmt.Print("Are you really sure ? You will delete all messages even if a user has a message in his tasks. Please enter again topic name to confirm: ")
		var confirmTopic string
		fmt.Scanln(&confirmTopic)

		if confirmTopic == topic {
			fmt.Printf("Please enter 'yes' to confirm removing all messages from %s: ", topic)
			var confirmYes string
			fmt.Scanln(&confirmYes)
			if confirmYes == "yes" {
				out, err := internal.Client().TopicTruncate(j)
				internal.Check(err)
				internal.Print(out)
				return
			}
		} else {
			fmt.Printf("Error. You enter %s instead of %s\n", confirmTopic, topic)
		}
		fmt.Println("Nothing done")
	}
}
示例#2
0
文件: verify.go 项目: ovh/tatcli
func userVerify(username, tokenVerify string) {
	verifyJSON, err := internal.Client().UserVerify(username, tokenVerify)
	internal.Check(err)

	// Display return to user (contains clear password)
	internal.Print(verifyJSON)

	if save && verifyJSON.Password != "" && verifyJSON.Username != "" && verifyJSON.URL != "" {
		verifyJSON.Message = ""
		jsonStr, err := json.MarshalIndent(verifyJSON, "", "  ")
		internal.Check(err)
		jsonStr = append(jsonStr, '\n')
		filename := internal.ConfigFile
		dir := path.Dir(filename)
		if _, err := os.Stat(dir); os.IsNotExist(err) {
			internal.Check(os.Mkdir(dir, 0740))
		}
		internal.Check(ioutil.WriteFile(filename, jsonStr, 0600))
	}
}
示例#3
0
文件: parameter.go 项目: ovh/tatcli
			Topic: args[0],
		}

		p.MaxLength, err = strconv.Atoi(args[1])
		internal.Check(err)
		p.CanForceDate, err = strconv.ParseBool(args[2])
		internal.Check(err)
		p.CanUpdateMsg, err = strconv.ParseBool(args[3])
		internal.Check(err)
		p.CanDeleteMsg, err = strconv.ParseBool(args[4])
		internal.Check(err)
		p.CanUpdateAllMsg, err = strconv.ParseBool(args[5])
		internal.Check(err)
		p.CanDeleteAllMsg, err = strconv.ParseBool(args[6])
		internal.Check(err)
		p.AdminCanUpdateAllMsg, err = strconv.ParseBool(args[7])
		internal.Check(err)
		p.AdminCanDeleteAllMsg, err = strconv.ParseBool(args[8])
		internal.Check(err)
		p.IsAutoComputeTags, err = strconv.ParseBool(args[9])
		internal.Check(err)
		p.IsAutoComputeLabels, err = strconv.ParseBool(args[10])
		internal.Check(err)
		out, err := internal.Client().TopicParameter(p)
		internal.Check(err)
		if internal.Verbose {
			internal.Print(out)
		}
	},
}
示例#4
0
文件: create.go 项目: ovh/tatcli
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")
		}
	},
}
示例#5
0
文件: create.go 项目: ovh/tatcli
package group

import (
	"strings"

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

var cmdGroupCreate = &cobra.Command{
	Use:   "create",
	Short: "create a new group: tatcli group create <groupname> <description>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) >= 2 {
			description := strings.Join(args[1:], " ")
			g, err := internal.Client().GroupCreate(tat.GroupJSON{Name: args[0], Description: description})
			internal.Check(err)
			internal.Print(g)
		} else {
			internal.Exit("Invalid argument: tatcli group create --help\n")
		}
	},
}
示例#6
0
文件: add.go 项目: ovh/tatcli
var cmdMessageAdd = &cobra.Command{
	Use:     "add",
	Aliases: []string{"a"},
	Short:   "tatcli message add [--dateCreation=timestamp] <topic> <my message>",
	Long: `Add a message to a Topic:
		tatcli message add /Private/firstname.lastname my new messsage
		`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) >= 2 {
			topic := args[0]
			message := strings.Join(args[1:], " ")
			msg, err := Create(topic, message)
			internal.Check(err)
			if internal.Verbose {
				internal.Print(msg)
			}
		} else {
			internal.Exit("Invalid argument to add a message: tatcli msg add --help\n")
		}
	},
}

// Create creates a message in specified topic
func Create(topic, message string) (*tat.MessageJSONOut, error) {
	m := tat.MessageJSON{Text: message, Topic: topic}
	if dateCreation > 0 {
		m.DateCreation = float64(dateCreation)
	}
	for _, label := range cmdLabel {
		s := strings.Split(label, ";")