<commit_before>package main

import (
	"flag"
	"fmt"
	"os"
	"os/user"
	"strings"

	"code.google.com/p/go-netrc/netrc"
	"github.com/codegangsta/cli"
)

const (
	ErrInvalidCommand = iota
	ErrInvalidNetrc
)

func main() {
	app := cli.NewApp()
	app.Name = "netrc"
	app.Usage = "Manage your netrc file."
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "netrc-path",
			Value: defaultNetrc(),
			Usage: "Path to the netrc file",
		},
	}
	app.Commands = []cli.Command{
		{
			Name:      "list",
			ShortName: "l",
			Usage:     "List netrc entries.",
			Action:    listCommand,
		},
		{
			Name:      "password",
			ShortName: "p",
			Usage:     "Show password for a machine.",
			Action:    passwordCommand,
		},
	}

	app.Run(os.Args)
}

type formattableMachine struct {
	*netrc.Machine
	showPw bool
}

func (m formattableMachine) Print() {
	var v []string
	if m.showPw {
		v = append(v, m.Machine.Password)
	} else {
		v = append(v, m.Machine.Name, m.Machine.Login)
	}

	fmt.Print(strings.Join(v, " "))
}

func listCommand(c *cli.Context) {
	filter, machines := cmdSetup(c)
	printMachines(machines, filter, false)
}

func passwordCommand(c *cli.Context) {
	filter, machines := cmdSetup(c)
	if filter == "" {
		fmt.Println("Provide a machine name.")
		os.Exit(ErrInvalidCommand)
	}
	printMachines(machines, filter, true)
}

func cmdSetup(c *cli.Context) (string, []*netrc.Machine) {
	filter := c.Args().First()
	machines, _, err := netrc.ParseFile(c.GlobalString("netrc-path"))
	if err != nil {
		flag.Usage()
		os.Exit(ErrInvalidNetrc)
	}
	return filter, machines
}

func printMachines(machines []*netrc.Machine, filter string, showPw bool) {
	printNewLine := false

	for _, m := range filterMachines(machines, filter) {
		if printNewLine {
			fmt.Println()
		}
		printNewLine = true

		formattableMachine{m, showPw}.Print()<commit_msg>Clean up entry points<commit_after>package main

import (
	"flag"
	"fmt"
	"os"
	"os/user"
	"strings"

	"code.google.com/p/go-netrc/netrc"
	"github.com/codegangsta/cli"
)

const (
	ErrInvalidCommand = iota
	ErrInvalidNetrc
)

func main() {
	app := cli.NewApp()
	app.Name = "netrc"
	app.Usage = "Manage your netrc file."
	app.Author = "<EMAIL>"
	app.Version = "0.0.1"
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "netrc-path",
			Value: defaultNetrc(),
			Usage: "Path to the netrc file",
		},
	}
	app.Commands = []cli.Command{
		{
			Name:      "list",
			ShortName: "l",
			Usage:     "List netrc entries.",
			Action:    listCommand,
		},
		{
			Name:      "password",
			ShortName: "p",
			Usage:     "Show password for a machine.",
			Action:    passwordCommand,
		},
	}
	app.CommandNotFound = func(c *cli.Context, cmd string) {
		fmt.Println(app.Usage)
		os.Exit(ErrInvalidCommand)
	}
	app.Action = listCommand

	app.EnableBashCompletion = true
	app.Run(os.Args)
}

type formattableMachine struct {
	*netrc.Machine
	showPw bool
}

func (m formattableMachine) Print() {
	var v []string
	if m.showPw {
		v = append(v, m.Machine.Password)
	} else {
		v = append(v, m.Machine.Name, m.Machine.Login)
	}

	fmt.Print(strings.Join(v, " "))
}

func listCommand(c *cli.Context) {
	filter, machines := cmdSetup(c)
	printMachines(machines, filter, false)
}

func passwordCommand(c *cli.Context) {
	filter, machines := cmdSetup(c)
	if filter == "" {
		fmt.Println(c.Command.Usage)
		os.Exit(ErrInvalidCommand)
	}
	printMachines(machines, filter, true)
}

func cmdSetup(c *cli.Context) (string, []*netrc.Machine) {
	filter := c.Args().First()
	machines, _, err := netrc.ParseFile(c.GlobalString("netrc-path"))
	if err != nil {
		flag.Usage()
		os.Exit(ErrInvalidNetrc)
	}
	return filter, machines
}

func printMachines(machines []*netrc.Machine, filter string, showPw bool) {
	printNewLine := false

	for _, m := range filterMachines(machines, filter) {
		if printNewLine {
			fmt.Println()
		}
		printNewLine = true

		formattableMachine{m, showPw}.Print()
{'fraction_non_alphanumeric': 0.15291698792084296, 'fraction_numerical': 0.0007710100231303007, 'mean_word_length': 3.584216725559482, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1898430', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1491, 'n_words': 316}