<commit_before>// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.

package engine

import (
	"regexp"
	"sort"
	"strings"

	"github.com/keybase/client/go/libkb"
	keybase1 "github.com/keybase/client/go/protocol/keybase1"
	jsonw "github.com/keybase/go-jsonw"
)

type TrackList []*libkb.TrackChainLink

func (tl TrackList) Len() int {
	return len(tl)
}

func (tl TrackList) Swap(i, j int) {
	tl[i], tl[j] = tl[j], tl[i]
}

func (tl TrackList) Less(i, j int) bool {
	return strings.ToLower(tl[i].ToDisplayString()) < strings.ToLower(tl[j].ToDisplayString())
}

type ListTrackingEngineArg struct {
	JSON         bool
	Verbose      bool
	Filter       string
	ForAssertion string
}

type ListTrackingEngine struct {
	arg         *ListTrackingEngineArg
	tableResult []keybase1.UserSummary
	jsonResult  string
	libkb.Contextified
}

func NewListTrackingEngine(arg *ListTrackingEngineArg, g *libkb.GlobalContext) *ListTrackingEngine {
	return &ListTrackingEngine{
		arg:          arg,
		Contextified: libkb.NewContextified(g),
	}
}

func (e *ListTrackingEngine) Name() string {
	return "ListTracking"
}

func (e *ListTrackingEngine) Prereqs() Prereqs { return Prereqs{} }

func (e *ListTrackingEngine) RequiredUIs() []libkb.UIKind { return []libkb.UIKind{} }

func (e *ListTrackingEngine) SubConsumers() []libkb.UIConsumer { return nil }

func (e *ListTrackingEngine) Run(ctx *Context) (err error) {

	var arg libkb.LoadUserArg

	if len(e.arg.ForAssertion) > 0 {
		arg = libkb.NewLoadUserByNameArg(e.G(), e.arg.ForAssertion)
	} else {
		arg.Self = true
	}

	err = e.G().GetFullSelfer().WithUser(arg, func(user *libkb.User) error {
		if user == nil {
			return libkb.UserNotFoundError{}
		}

		var trackList TrackList
		var err error
		trackList = user.IDTable().GetTrackList()

		trackList, err = filterRxx(trackList, e.arg.Filter)
		if err != nil {
			return err
		}
		sort.Sort(trackList)

		if e.arg.JSON {
			return e.runJSON(trackList, e.arg.Verbose)
		}
		return e.runTable(trackList)
	})

	return err<commit_msg>test user.IDTable() before use (#6468)<commit_after>// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.

package engine

import (
	"regexp"
	"sort"
	"strings"

	"github.com/keybase/client/go/libkb"
	keybase1 "github.com/keybase/client/go/protocol/keybase1"
	jsonw "github.com/keybase/go-jsonw"
)

type TrackList []*libkb.TrackChainLink

func (tl TrackList) Len() int {
	return len(tl)
}

func (tl TrackList) Swap(i, j int) {
	tl[i], tl[j] = tl[j], tl[i]
}

func (tl TrackList) Less(i, j int) bool {
	return strings.ToLower(tl[i].ToDisplayString()) < strings.ToLower(tl[j].ToDisplayString())
}

type ListTrackingEngineArg struct {
	JSON         bool
	Verbose      bool
	Filter       string
	ForAssertion string
}

type ListTrackingEngine struct {
	arg         *ListTrackingEngineArg
	tableResult []keybase1.UserSummary
	jsonResult  string
	libkb.Contextified
}

func NewListTrackingEngine(arg *ListTrackingEngineArg, g *libkb.GlobalContext) *ListTrackingEngine {
	return &ListTrackingEngine{
		arg:          arg,
		Contextified: libkb.NewContextified(g),
	}
}

func (e *ListTrackingEngine) Name() string {
	return "ListTracking"
}

func (e *ListTrackingEngine) Prereqs() Prereqs { return Prereqs{} }

func (e *ListTrackingEngine) RequiredUIs() []libkb.UIKind { return []libkb.UIKind{} }

func (e *ListTrackingEngine) SubConsumers() []libkb.UIConsumer { return nil }

func (e *ListTrackingEngine) Run(ctx *Context) (err error) {

	var arg libkb.LoadUserArg

	if len(e.arg.ForAssertion) > 0 {
		arg = libkb.NewLoadUserByNameArg(e.G(), e.arg.ForAssertion)
	} else {
		arg.Self = true
	}

	err = e.G().GetFullSelfer().WithUser(arg, func(user *libkb.User) error {
		if user == nil {
			return libkb.UserNotFoundError{}
		}

		var trackList TrackList
		var err error
		if idTable := user.IDTable(); idTable != nil {
			trackList = idTable.GetTrackList()
		}

		trackList, err = filterRxx(trackList, e.arg.Filter)
		if err != nil {
			return err
		}
		sort.Sort(trackList)

		if e.arg.JSON {
			return e.runJSON(trackList, e.arg.Verbose)
		}
		return e.runTable(trackList)
	})

	return err
{'fraction_non_alphanumeric': 0.12322611163670766, 'fraction_numerical': 0.004730368968779565, 'mean_word_length': 4.0465393794749405, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3595833', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1529, 'n_words': 364}