<commit_before>package command

import (
	"flag"
	"fmt"
	"strings"

	"github.com/funkygao/gafka/ctx"
	"github.com/funkygao/gafka/zk"
	"github.com/funkygao/gocli"
	"github.com/funkygao/golib/color"
	"github.com/funkygao/golib/gofmt"
)

type Kguard struct {
	Ui  cli.Ui
	Cmd string

	zone string
}

func (this *Kguard) Run(args []string) (exitCode int) {
	cmdFlags := flag.NewFlagSet("kguard", flag.ContinueOnError)
	cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
	cmdFlags.StringVar(&this.zone, "z", ctx.ZkDefaultZone(), "")
	if err := cmdFlags.Parse(args); err != nil {
		return 2
	}

	zkzone := zk.NewZkZone(zk.DefaultConfig(this.zone, ctx.ZoneZkAddrs(this.zone)))
	data, stat, err := zkzone.Conn().Get("/" + zk.KguardLeaderPath)
	if err != nil {
		this.Ui.Error(fmt.Sprintf("%s %v", zk.KguardLeaderPath, err.Error()))
		return
	}

	this.Ui.Output(fmt.Sprintf("%s %s", color.Green(string(data)),
		gofmt.PrettySince(zk.ZkTimestamp(stat.Mtime).Time())))

	return
}

func (*Kguard) Synopsis() string {
	return "List online kguard instances"
}

func (this *Kguard) Help() string {
	help := fmt.Sprintf(`
Usage: %s kateway -z zone [options]

    List online kguard instances

`, this.Cmd)
	return strings.TrimSpace(help)
}
<commit_msg>display kguard candidates and leader<commit_after>package command

import (
	"flag"
	"fmt"
	"strings"

	"github.com/funkygao/gafka/ctx"
	"github.com/funkygao/gafka/zk"
	"github.com/funkygao/gocli"
	"github.com/funkygao/golib/color"
	"github.com/funkygao/golib/gofmt"
)

type Kguard struct {
	Ui  cli.Ui
	Cmd string

	zone string
}

func (this *Kguard) Run(args []string) (exitCode int) {
	cmdFlags := flag.NewFlagSet("kguard", flag.ContinueOnError)
	cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
	cmdFlags.StringVar(&this.zone, "z", ctx.ZkDefaultZone(), "")
	if err := cmdFlags.Parse(args); err != nil {
		return 2
	}

	zkzone := zk.NewZkZone(zk.DefaultConfig(this.zone, ctx.ZoneZkAddrs(this.zone)))
	data, stat, err := zkzone.Conn().Get("/" + zk.KguardLeaderPath)
	if err != nil {
		this.Ui.Error(fmt.Sprintf("%s %v", zk.KguardLeaderPath, err.Error()))
		return
	}

	children, _, _ := zkzone.Conn().Children("/" + zk.KguardLeaderPath)

	this.Ui.Output(fmt.Sprintf("%s(out of %d candidates) up: %s",
		color.Green(string(data)),
		len(children),
		gofmt.PrettySince(zk.ZkTimestamp(stat.Mtime).Time())))

	return
}

func (*Kguard) Synopsis() string {
	return "List online kguard instances"
}

func (this *Kguard) Help() string {
	help := fmt.Sprintf(`
Usage: %s kateway -z zone [options]

    List online kguard instances

`, this.Cmd)
	return strings.TrimSpace(help)
}

{'fraction_non_alphanumeric': 0.17022900763358778, 'fraction_numerical': 0.0007633587786259542, 'mean_word_length': 4.471816283924843, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3273332', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1028, 'n_words': 198}