<commit_before>// Copyright 2016 The LUCI Authors. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.

package main

import (
	"flag"
	"os"
	"os/signal"

	"github.com/maruel/subcommands"
	"golang.org/x/net/context"

	"github.com/luci/luci-go/client/authcli"
	"github.com/luci/luci-go/common/auth"
	"github.com/luci/luci-go/common/cli"
	log "github.com/luci/luci-go/common/logging"
	"github.com/luci/luci-go/common/logging/gologger"
)

type application struct {
	cli.Application

	authFlags  authcli.Flags
	layoutPath string
	workers    int

	layout deployLayout
	tools  tools
}

func (a *application) addFlags(fs *flag.FlagSet) {
	fs.StringVar(&a.layoutPath, "layout", a.layoutPath,
		"Path to the base layout file.")
	fs.IntVar(&a.workers, "workers", 0,
		"Maximum number of workers to use. If <= 0, no limit will be applied.")
}

func (a *application) runWork(c context.Context, fn func(*work) error) error {
	return runWork(c, a.workers, &a.tools, fn)
}

func mainImpl(args []string) int {
	authOptions := auth.Options{
		Scopes: []string{
			"https://www.googleapis.com/auth/cloud-platform",
		},
	}

	c := gologger.StdConfig.Use(context.Background())
	a := application{
		Application: cli.Application{
			Name:    os.Args[0],
			Title:   "LUCI Deployment Tool",
			Context: func(context.Context) context.Context { return c },
			Commands: []*subcommands.Command{
				subcommands.CmdHelp,
				&cmdCheckout,
				&cmdDeploy,
				&cmdManage,

				authcli.SubcommandLogin(authOptions, "auth-login", false),
				authcli.SubcommandLogout(authOptions, "auth-logout", false),
				authcli.SubcommandInfo(authOptions, "auth-info", false),
			},
		},
	}
	logFlags := log.Config{
		Level: log.Warning,
	}

	var fs flag.FlagSet
	logFlags.AddFlags(&fs)
	a.authFlags.Register(&fs, authOptions)
	a.addFlags(&fs)
	if err := fs.Parse(args); err != nil {
		log.WithError(err).Errorf(c, "Failed to parse flags.")
		return 1
	}
	c = logFlags.Set(c)

	// Install a signal handler to cancel everything in response to a Ctrl+C.
	var cancelFunc context.CancelFunc
	c, cancelFunc = context.WithCancel(c)
	signalC := make(chan os.Signal, 1)
	signal.Notify(signalC, os.Interrupt)
	go func(c context.Context) {
		signalled := false
		for range signalC {
			if !signalled {
				signalled = true

				// First '^C'; soft-terminate
				log.Infof(c, "Received Control-C (keyboard interrupt), shutting down. Interrupt again for immediate exit.")
				cancelFunc()
			} else {
				// Multiple '^C'; terminate immediately
				os.Exit(1)
			}
		}
	}(c)
	defer func() {
		signal.Stop(signalC)
		close(signalC)
	}()

	// Load our layout file.
	if err := a.layout.load(c, a.layoutPath); err != nil {
		logError(c, err, "Failed to load layout file from [%s]", a.layoutPath)
		return 1
	}

	// Run our subcommand (and parse subcommand flags).
	return subcommands.Run(&a, fs.Args())
}

func main() {
	os.Exit(mainImpl(os.Args[1:]))
}
<commit_msg>Remove unnecessary usage of 'auth' and 'authcli' from luci_deploy.<commit_after>// Copyright 2016 The LUCI Authors. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.

package main

import (
	"flag"
	"os"
	"os/signal"

	"github.com/maruel/subcommands"
	"golang.org/x/net/context"

	"github.com/luci/luci-go/common/cli"
	log "github.com/luci/luci-go/common/logging"
	"github.com/luci/luci-go/common/logging/gologger"
)

type application struct {
	cli.Application

	layoutPath string
	workers    int

	layout deployLayout
	tools  tools
}

func (a *application) addFlags(fs *flag.FlagSet) {
	fs.StringVar(&a.layoutPath, "layout", a.layoutPath,
		"Path to the base layout file.")
	fs.IntVar(&a.workers, "workers", 0,
		"Maximum number of workers to use. If <= 0, no limit will be applied.")
}

func (a *application) runWork(c context.Context, fn func(*work) error) error {
	return runWork(c, a.workers, &a.tools, fn)
}

func mainImpl(args []string) int {
	c := gologger.StdConfig.Use(context.Background())
	a := application{
		Application: cli.Application{
			Name:    os.Args[0],
			Title:   "LUCI Deployment Tool",
			Context: func(context.Context) context.Context { return c },
			Commands: []*subcommands.Command{
				subcommands.CmdHelp,
				&cmdCheckout,
				&cmdDeploy,
				&cmdManage,
			},
		},
	}
	logFlags := log.Config{
		Level: log.Warning,
	}

	var fs flag.FlagSet
	logFlags.AddFlags(&fs)
	a.addFlags(&fs)
	if err := fs.Parse(args); err != nil {
		log.WithError(err).Errorf(c, "Failed to parse flags.")
		return 1
	}
	c = logFlags.Set(c)

	// Install a signal handler to cancel everything in response to a Ctrl+C.
	var cancelFunc context.CancelFunc
	c, cancelFunc = context.WithCancel(c)
	signalC := make(chan os.Signal, 1)
	signal.Notify(signalC, os.Interrupt)
	go func(c context.Context) {
		signalled := false
		for range signalC {
			if !signalled {
				signalled = true

				// First '^C'; soft-terminate
				log.Infof(c, "Received Control-C (keyboard interrupt), shutting down. Interrupt again for immediate exit.")
				cancelFunc()
			} else {
				// Multiple '^C'; terminate immediately
				os.Exit(1)
			}
		}
	}(c)
	defer func() {
		signal.Stop(signalC)
		close(signalC)
	}()

	// Load our layout file.
	if err := a.layout.load(c, a.layoutPath); err != nil {
		logError(c, err, "Failed to load layout file from [%s]", a.layoutPath)
		return 1
	}

	// Run our subcommand (and parse subcommand flags).
	return subcommands.Run(&a, fs.Args())
}

func main() {
	os.Exit(mainImpl(os.Args[1:]))
}

{'fraction_non_alphanumeric': 0.13961387200572042, 'fraction_numerical': 0.0050053628888094386, 'mean_word_length': 3.631622516556291, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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': '7639861', 'n_tokens_mistral': 2153, 'n_tokens_neox': 1959, 'n_words': 520}