<commit_before>package main

import (
	"fmt"
	"log"
	"text/tabwriter"

	update "github.com/coreos-inc/updatectl/client/update/v1"
)

var (
	clientUpdateFlags struct {
		groupId string
		appId   string
		start   int64
		end     int64
	}

	cmdListClientUpdates = &Command{
		Name:        "list-clientupdates",
		Usage:       "[OPTION]...",
		Description: "Generates a list of client updates.",
		Run:         listClientUpdates,
	}

	cmdListAppVersions = &Command{
		Name:        "list-appversions",
		Usage:       "[OPTION]...",
		Description: "Generates a list of apps/versions with client count.",
		Run:         listAppVersions,
	}
)

func init() {
	cmdListClientUpdates.Flags.StringVar(&clientUpdateFlags.groupId, "group-id", "", "Group id")
	cmdListClientUpdates.Flags.StringVar(&clientUpdateFlags.appId, "app-id", "", "App id")
	cmdListClientUpdates.Flags.Int64Var(&clientUpdateFlags.start, "start", 0, "Start date filter")
	cmdListClientUpdates.Flags.Int64Var(&clientUpdateFlags.end, "end", 0, "End date filter")

	cmdListAppVersions.Flags.Int64Var(&clientUpdateFlags.start, "start", 0, "Start date filter")
	cmdListAppVersions.Flags.Int64Var(&clientUpdateFlags.end, "end", 0, "End date filter")
}

func listClientUpdates(args []string, service *update.Service, out *tabwriter.Writer) int {
	call := service.Clientupdate.List()
	call.DateStart(clientUpdateFlags.start)
	call.DateEnd(clientUpdateFlags.end)
	call.GroupId(clientUpdateFlags.groupId)
	call.AppId(clientUpdateFlags.appId)
	list, err := call.Do()

	if err != nil {
		log.Fatal(err)
	}

	fmt.Fprintln(out, "AppID\tClientID\tVersion\tLastSeen\tGroup\tStatus\tOEM")
	for _, cl := range list.Items {
		fmt.Fprintf(out, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n", cl.AppId,
			cl.ClientId, cl.Version, cl.LastSeen, cl.GroupId,
			cl.Status, cl.Oem)
	}
	out.Flush()
	return OK
}

func listAppVersions(args []string, service *update.Service, out *tabwriter.Writer) int {
	call := service.Appversion.List()

	call.GroupId(clientUpdateFlags.groupId)
	call.AppId(clientUpdateFlags.appId)

	if clientUpdateFlags.start != 0 {
		call.DateStart(clientUpdateFlags.start)
	}

	if clientUpdateFlags.end != 0 {
		call.DateEnd(clientUpdateFlags.end)
	}

	list, err := call.Do()

	if err != nil {
		log.Fatal(err)
	}

	fmt.Fprintln(out, "AppID\tGroupID\tVersion\tClients")
	for _, cl := range list.Items {<commit_msg>refactor(client_update): require app-id and group-id flags<commit_after>package main

import (
	"fmt"
	"log"
	"text/tabwriter"

	update "github.com/coreos-inc/updatectl/client/update/v1"
)

var (
	clientUpdateFlags struct {
		groupId StringFlag
		appId   StringFlag
		start   int64
		end     int64
	}

	cmdListClientUpdates = &Command{
		Name:        "list-clientupdates",
		Usage:       "[OPTION]...",
		Description: "Generates a list of client updates.",
		Run:         listClientUpdates,
	}

	cmdListAppVersions = &Command{
		Name:        "list-appversions",
		Usage:       "[OPTION]...",
		Description: "Generates a list of apps/versions with client count.",
		Run:         listAppVersions,
	}
)

func init() {
	cmdListClientUpdates.Flags.Var(&clientUpdateFlags.groupId, "group-id", "Group id")
	cmdListClientUpdates.Flags.Var(&clientUpdateFlags.appId, "app-id", "App id")
	cmdListClientUpdates.Flags.Int64Var(&clientUpdateFlags.start, "start", 0, "Start date filter")
	cmdListClientUpdates.Flags.Int64Var(&clientUpdateFlags.end, "end", 0, "End date filter")

	cmdListAppVersions.Flags.Var(&clientUpdateFlags.groupId, "group-id", "Group id")
	cmdListAppVersions.Flags.Var(&clientUpdateFlags.appId, "app-id", "App id")
	cmdListAppVersions.Flags.Int64Var(&clientUpdateFlags.start, "start", 0, "Start date filter")
	cmdListAppVersions.Flags.Int64Var(&clientUpdateFlags.end, "end", 0, "End date filter")
}

func listClientUpdates(args []string, service *update.Service, out *tabwriter.Writer) int {
	if clientUpdateFlags.appId.Get() == nil ||
		clientUpdateFlags.groupId.Get() == nil {
		return ERROR_USAGE
	}

	call := service.Clientupdate.List()
	call.DateStart(clientUpdateFlags.start)
	call.DateEnd(clientUpdateFlags.end)
	call.GroupId(clientUpdateFlags.groupId.String())
	call.AppId(clientUpdateFlags.appId.String())
	list, err := call.Do()

	if err != nil {
		log.Fatal(err)
	}

	fmt.Fprintln(out, "AppID\tClientID\tVersion\tLastSeen\tGroup\tStatus\tOEM")
	for _, cl := range list.Items {
		fmt.Fprintf(out, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n", cl.AppId,
			cl.ClientId, cl.Version, cl.LastSeen, cl.GroupId,
			cl.Status, cl.Oem)
	}
	out.Flush()
	return OK
}

func listAppVersions(args []string, service *update.Service, out *tabwriter.Writer) int {
	if clientUpdateFlags.appId.Get() == nil ||
		clientUpdateFlags.groupId.Get() == nil {
		return ERROR_USAGE
	}

	call := service.Appversion.List()

	call.GroupId(clientUpdateFlags.groupId.String())
	call.AppId(clientUpdateFlags.appId.String())

	if clientUpdateFlags.start != 0 {
		call.DateStart(clientUpdateFlags.start)
	}

	if clientUpdateFlags.end != 0 {
		call.DateEnd(clientUpdateFlags.end)
	}

	list, err := call.Do()

	if err != nil {
		log.Fatal(err)
	}

	fmt.Fprintln(out, "AppID\tGroupID\tVersion\tClients")
	for _, cl := range list.Items {
{'fraction_non_alphanumeric': 0.14379972831360371, 'fraction_numerical': 0.007374345041723268, 'mean_word_length': 4.379958246346555, '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': '1824870', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1840, 'n_words': 341}