<commit_before>package netrc

import (
	"errors"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"os/user"
	"path/filepath"
	"strings"
)

// A simple credential struct for a username and password
type Cred struct {
	User string
	Pass string
}

// A struct for the Netrc
//	Path is the netrc filepath
//	Creds is a map of string keys that have pointers to Cred structs
//	The keys relate to the service name from the netrc or 'default'
//	ex: 'machine github.com' Then the key is github.com
type Netrc struct {
	Path  string
	Creds map[string]*Cred
}

// Opens the given path if it exists
// If the path is invalid a fatal error is thrown
// A new Netrc is created and the file is read into the Creds map
// A pointer to the Netrc will always be returned
func Open(path string) *Netrc {
	filePath := FilePath(path)
	if !FileExists(filePath) {
		log.Fatalf("Netrc file does not exist in '%s'", filePath)
	}

	n := new(Netrc)
	n.Path = filePath
	n.Read()

	return n
}

// Creates a new Cred struct with a user and pass
//	u: a username
//	p: a password
//	if either u or p are the empty string an error is returned
//	otherwise a pointer to the struct is returned
func CreateCred(u string, p string) (*Cred, error) {
	if u == "" || p == "" {<commit_msg>Add OpenDefault method for file<commit_after>package netrc

import (
	"errors"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"os/user"
	"path/filepath"
	"strings"
)

// A simple credential struct for a username and password
type Cred struct {
	User string
	Pass string
}

// A struct for the Netrc
//	Path is the netrc filepath
//	Creds is a map of string keys that have pointers to Cred structs
//	The keys relate to the service name from the netrc or 'default'
//	ex: 'machine github.com' Then the key is github.com
type Netrc struct {
	Path  string
	Creds map[string]*Cred
}

// A convenience method for opening the default .netrc
//	Probably in $HOME/.netrc
func OpenDefault() *Netrc {
	return Open("")
}

// Opens the given path if it exists
// If the path is invalid a fatal error is thrown
// A new Netrc is created and the file is read into the Creds map
// A pointer to the Netrc will always be returned
func Open(path string) *Netrc {
	filePath := FilePath(path)
	if !FileExists(filePath) {
		log.Fatalf("Netrc file does not exist in '%s'", filePath)
	}

	n := new(Netrc)
	n.Path = filePath
	n.Read()

	return n
}

// Creates a new Cred struct with a user and pass
//	u: a username
//	p: a password
//	if either u or p are the empty string an error is returned
//	otherwise a pointer to the struct is returned
func CreateCred(u string, p string) (*Cred, error) {
	if u == "" || p == "" {
{'fraction_non_alphanumeric': 0.09881724532621138, 'fraction_numerical': 0.0, 'mean_word_length': 3.284313725490196, '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': '3759729', 'n_tokens_mistral': 883, 'n_tokens_neox': 863, 'n_words': 394}