<commit_before>package main

import (
	"errors"
	"os"
	"path/filepath"
	"runtime"
	"strings"

	"github.com/dickeyxxx/netrc"
)

// ErrHelp means the user didn't type a valid command and we need to display help.
var ErrHelp = errors.New("help")

// ErrAppNeeded means the command needs an app context and one was not found.
var ErrAppNeeded = errors.New("No app specified.\nRun this command from an app folder or specify which app to use with --app APP")

// ErrOrgNeeded means the command needs an org context and one was not found.
var ErrOrgNeeded = errors.New("No org specified.\nRun this command with --org or by setting HEROKU_ORGANIZATION")

// Cli handles parsing and dispatching of commands
type Cli struct {
	Topics   TopicSet
	Commands CommandSet
}

// Run parses command line arguments and runs the associated command or help.
// Also does lookups for app name and/or auth token if the command needs it.
func (cli *Cli) Run(args []string) (err error) {
	ctx := &Context{}
	if len(args) < 2 {
		return ErrHelp
	}
	ctx.Topic, ctx.Command = cli.ParseCmd(args[1])
	if ctx.Command == nil {
		return ErrHelp
	}
	if ctx.Command.VariableArgs {
		ctx.Args, ctx.Flags, ctx.App, err = parseVarArgs(ctx.Command, args[2:])
	} else {
		ctx.Args, ctx.Flags, ctx.App, err = parseArgs(ctx.Command, args[2:])
	}
	if err != nil {
		return err
	}
	if ctx.Command.NeedsApp || ctx.Command.WantsApp {
		if ctx.App == "" {
			ctx.App = app()
		}
		if ctx.App == "" && ctx.Command.NeedsApp {
			return ErrAppNeeded
		}
	}
	if ctx.Command.NeedsOrg || ctx.Command.WantsOrg {
		if org, ok := ctx.Flags["org"].(string); ok {
			ctx.Org = org
		} else {
			ctx.Org = os.Getenv("HEROKU_ORGANIZATION")
			if ctx.Org == "" && ctx.Command.NeedsOrg {
				return ErrOrgNeeded
			}
		}
	}
	if ctx.Command.NeedsAuth {
		ctx.APIToken = auth()
		ctx.Auth.Password = ctx.APIToken<commit_msg>Slight formatting change to match needsApp<commit_after>package main

import (
	"errors"
	"os"
	"path/filepath"
	"runtime"
	"strings"

	"github.com/dickeyxxx/netrc"
)

// ErrHelp means the user didn't type a valid command and we need to display help.
var ErrHelp = errors.New("help")

// ErrAppNeeded means the command needs an app context and one was not found.
var ErrAppNeeded = errors.New("No app specified.\nRun this command from an app folder or specify which app to use with --app APP")

// ErrOrgNeeded means the command needs an org context and one was not found.
var ErrOrgNeeded = errors.New("No org specified.\nRun this command with --org or by setting HEROKU_ORGANIZATION")

// Cli handles parsing and dispatching of commands
type Cli struct {
	Topics   TopicSet
	Commands CommandSet
}

// Run parses command line arguments and runs the associated command or help.
// Also does lookups for app name and/or auth token if the command needs it.
func (cli *Cli) Run(args []string) (err error) {
	ctx := &Context{}
	if len(args) < 2 {
		return ErrHelp
	}
	ctx.Topic, ctx.Command = cli.ParseCmd(args[1])
	if ctx.Command == nil {
		return ErrHelp
	}
	if ctx.Command.VariableArgs {
		ctx.Args, ctx.Flags, ctx.App, err = parseVarArgs(ctx.Command, args[2:])
	} else {
		ctx.Args, ctx.Flags, ctx.App, err = parseArgs(ctx.Command, args[2:])
	}
	if err != nil {
		return err
	}
	if ctx.Command.NeedsApp || ctx.Command.WantsApp {
		if ctx.App == "" {
			ctx.App = app()
		}
		if ctx.App == "" && ctx.Command.NeedsApp {
			return ErrAppNeeded
		}
	}
	if ctx.Command.NeedsOrg || ctx.Command.WantsOrg {
		if org, ok := ctx.Flags["org"].(string); ok {
			ctx.Org = org
		} else {
			ctx.Org = os.Getenv("HEROKU_ORGANIZATION")
		}
		if ctx.Org == "" && ctx.Command.NeedsOrg {
			return ErrOrgNeeded
		}
	}
	if ctx.Command.NeedsAuth {
		ctx.APIToken = auth()
		ctx.Auth.Password = ctx.APIToken
{'fraction_non_alphanumeric': 0.1201281366791244, 'fraction_numerical': 0.002135611318739989, 'mean_word_length': 3.423848878394333, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6279105', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1289, 'n_words': 412}