<commit_before>package main

import (
	"fmt"
	"os"
	"time"
	"bufio"

	"crypto/rand"
	"golang.org/x/crypto/ssh/terminal"

	"github.com/atotto/clipboard"
	"gopkg.in/alecthomas/kingpin.v2"
	"github.com/zalando/go-keyring"

	"encoding/binary"

	"sort"
	"os/exec"
	"bytes"
	"github.com/crholm/pl/vault"
)

func toClipboard(password string, secondsInClipboard int) {
	clipboard.WriteAll(password)

	if (secondsInClipboard > 0) {
		time.Sleep(time.Duration(secondsInClipboard) * time.Second)
		clip, _ := clipboard.ReadAll()
		if password == clip {
			clipboard.WriteAll("")
		}
	}
}

func createPassword(name string, pwdLen int, noExtras bool) (*vault.Password) {

	a := "0<PASSWORD>789"
	a += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	a += "abcdefghijklmnopqrstuvwxyz"

	if (!noExtras) {
		a += "<>|!#%&/()=+-_.:,;'*@${[]}\\ "
	}

	aLen := uint64(len(a))

	buf := ""
	for i := 0; i < pwdLen; i++ {
		b := make([]byte, 8)
		rand.Read(b)
		c := binary.BigEndian.Uint64(b)
		buf += string(a[c % aLen])
	}

	pwd := vault.Password{Name: name, Password:buf};


	return &pwd
}

var (
	dir string
	app = kingpin.New("pl", "A command-line password protection application.").Author("<NAME>")
	key = app.Flag("key", "The key for decrypting the password vault, if not piped into the application").Short('k').String()
	path = app.Flag("path", "Path to key vault, if deault location is not desired ($HOME/.pl)").Short('p').String()
	stdin = app.Flag("stdin", "Reads key from stdin").Short('s').Bool()

	ini = app.Command("init", "Init your vault")

	mk = app.Command("mk", "Makes and save a new password.")
	mkName = mk.Arg("name", "Name of new password").Required().String()
	mkLength = mk.Arg("length", "Length of new password").Default("14").Int()
	mkNoExtra = mk.Flag("noextras", "Exclude specical characters from password").Short('n').Bool()

	set = app.Command("set", "Saves a new password.")
	setName = set.Arg("name", "Name of new password").Required().String()
	setPassword = set.Arg("password", "<PASSWORD>").String()

	setMetadata = app.Command("set-metadata", "Alter metadata for password")
	setMetadataPassword = setMetadata.Arg("name", "Name of password").Required().String()
	setMetadataKey = setMetadata.Arg("key", "metadata key").Required().String()
	setMetadataValue = setMetadata.Arg("value", "metadata value").Required().String()

	rmMetadata = app.Command("rm-metadata", "Remove metadata for password")
	rmMetadataPassword = rmMetadata.Arg("name", "Name of password").Required().String()
	rmMetadataKey = rmMetadata.Arg("key", "metadata key").Required().String()

	mv = app.Command("mv", "Rename password")
	mvFrom = mv.Arg("from", "Target password to be renamed").Required().String()
	mvTo = mv.Arg("to", "New password name").Required().String()

	ls = app.Command("ls", "List all password names")
	ll = app.Command("ll", "List all password names and metadata")

	cat = app.Command("cat", "Concatinates password to std out")
	catName = cat.Arg("name", "Name of password").Required().String()

	cp = app.Command("cp", "Copy password to clipboard")
	cpName = cp.Arg("name", "Name of password").Required().String()
	cpDuration = cp.Arg("duration", "The number of scound the password remains in clipboard").Default("0").Int()

	rm = app.Command("rm", "Removes a password")
	rmName = rm.Arg("name", "Name of password").Required().String()

	git = app.Command("git", "Straight up git support for the password vault. git cli must be installed to be availible")
	gitCommands = git.Arg("commands", "whatever it may be").Required().Strings()

	addKey = app.Command("add-key", "Add your vault key to systems keychain in order to avoid applying key each time")
	rmKey = app.Command("remove-key", "Remove your vault key to systems keychain")

	chkey = app.Command("chkey", "Change your vault key")

	chcost = app.Command("chcost", "Change scrypt cost settings")
	chcostN = chcost.Arg("N", "CPU workfactor [16384]").Required().Int()
	chcostR = chcost.Arg("r", "Memory cost factor [8]").Required().Int()
	chcostP = chcost.Arg("p", "Paralleization factor [2]").Required().Int()
)

func main() {

	var command string;
	if(len(os.Args) > 1 && os.Args[1] == "git"){
		command = "git"
	}else{
		command = kingpin.MustParse(app.Parse(os.Args[1:]))

	}
	if(len(*path) > 0){
		dir = *path
	}else{
		dir = os.Getenv("HOME") + "/.pl"
	}

	var vaultPassword string
	var m map[string]*vault.Password

	if command != git.FullCommand() && command != ini.FullCommand() {
		mp, vp := readKeyAndLoad()
		if mp == nil || vp == "" {
			return
		}

		vaultPassword = vp
		m = *mp
	}

	switch  command {

	case ini.FullCommand():<commit_msg>adding version<commit_after>package main

import (
	"fmt"
	"os"
	"time"
	"bufio"

	"crypto/rand"
	"golang.org/x/crypto/ssh/terminal"

	"github.com/atotto/clipboard"
	"gopkg.in/alecthomas/kingpin.v2"
	"github.com/zalando/go-keyring"

	"encoding/binary"

	"sort"
	"os/exec"
	"bytes"
	"github.com/crholm/pl/vault"
)

func toClipboard(password string, secondsInClipboard int) {
	clipboard.WriteAll(password)

	if (secondsInClipboard > 0) {
		time.Sleep(time.Duration(secondsInClipboard) * time.Second)
		clip, _ := clipboard.ReadAll()
		if password == clip {
			clipboard.WriteAll("")
		}
	}
}

func createPassword(name string, pwdLen int, noExtras bool) (*vault.Password) {

	a := "0123456789"
	a += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	a += "abcdefghijklmnopqrstuvwxyz"

	if (!noExtras) {
		a += "<>|!#%&/()=+-_.:,;'*@${[]}\\ "
	}

	aLen := uint64(len(a))

	buf := ""
	for i := 0; i < pwdLen; i++ {
		b := make([]byte, 8)
		rand.Read(b)
		c := binary.BigEndian.Uint64(b)
		buf += string(a[c % aLen])
	}

	pwd := vault.Password{Name: name, Password:buf};


	return &pwd
}

var (
	version = "1.0.0"
	dir string
	app = kingpin.New("pl", "Password locker is a command-line tool for managing your passwords").Author("<NAME>")
	key = app.Flag("key", "The key for decrypting the password vault, if not piped into the application").Short('k').String()
	path = app.Flag("path", "Path to key vault, if deault location is not desired ($HOME/.pl)").Short('p').String()
	stdin = app.Flag("stdin", "Reads key from stdin").Short('s').Bool()
	versionFlag = app.Flag("version", "print pl version").Short('v').Bool()

	ini = app.Command("init", "Init your vault")

	mk = app.Command("mk", "Makes and save a new password.")
	mkName = mk.Arg("name", "Name of new password").Required().String()
	mkLength = mk.Arg("length", "Length of new password").Default("14").Int()
	mkNoExtra = mk.Flag("noextras", "Exclude specical characters from password").Short('n').Bool()

	set = app.Command("set", "Saves a new password.")
	setName = set.Arg("name", "Name of new password").Required().String()
	setPassword = set.Arg("password", "<PASSWORD>").String()

	setMetadata = app.Command("set-metadata", "Alter metadata for password")
	setMetadataPassword = setMetadata.Arg("name", "Name of password").Required().String()
	setMetadataKey = setMetadata.Arg("key", "metadata key").Required().String()
	setMetadataValue = setMetadata.Arg("value", "metadata value").Required().String()

	rmMetadata = app.Command("rm-metadata", "Remove metadata for password")
	rmMetadataPassword = rmMetadata.Arg("name", "Name of password").Required().String()
	rmMetadataKey = rmMetadata.Arg("key", "metadata key").Required().String()

	mv = app.Command("mv", "Rename password")
	mvFrom = mv.Arg("from", "Target password to be renamed").Required().String()
	mvTo = mv.Arg("to", "New password name").Required().String()

	ls = app.Command("ls", "List all password names")
	ll = app.Command("ll", "List all password names and metadata")

	cat = app.Command("cat", "Concatinates password to std out")
	catName = cat.Arg("name", "Name of password").Required().String()

	cp = app.Command("cp", "Copy password to clipboard")
	cpName = cp.Arg("name", "Name of password").Required().String()
	cpDuration = cp.Arg("duration", "The number of scound the password remains in clipboard").Default("0").Int()

	rm = app.Command("rm", "Removes a password")
	rmName = rm.Arg("name", "Name of password").Required().String()

	git = app.Command("git", "Straight up git support for the password vault. git cli must be installed to be availible")
	gitCommands = git.Arg("commands", "whatever it may be").Required().Strings()

	addKey = app.Command("add-key", "Add your vault key to systems keychain in order to avoid applying key each time")
	rmKey = app.Command("remove-key", "Remove your vault key to systems keychain")

	chkey = app.Command("chkey", "Change your vault key")

	chcost = app.Command("chcost", "Change scrypt cost settings")
	chcostN = chcost.Arg("N", "CPU workfactor [16384]").Required().Int()
	chcostR = chcost.Arg("r", "Memory cost factor [8]").Required().Int()
	chcostP = chcost.Arg("p", "Paralleization factor [2]").Required().Int()
)

func main() {


	var command string;
	if(len(os.Args) > 1 && os.Args[1] == "git"){
		command = "git"
	}else if os.Args[1] == "--version" || os.Args[1] == "-v" {
		fmt.Println("pl version " + version)
		return;
	}else{
		command = kingpin.MustParse(app.Parse(os.Args[1:]))
	}
	if(len(*path) > 0){
		dir = *path
	}else{
		dir = os.Getenv("HOME") + "/.pl"
	}


	var vaultPassword string
	var m map[string]*vault.Password

	if command != git.FullCommand() && command != ini.FullCommand() {
		mp, vp := readKeyAndLoad()
		if mp == nil || vp == "" {
			return
		}

		vaultPassword = vp
		m = *mp
	}

	switch  command {

	case ini.FullCommand():
{'fraction_non_alphanumeric': 0.18459086078639744, 'fraction_numerical': 0.0066950053134962806, 'mean_word_length': 4.601785714285715, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 16, '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': '3027730', 'n_tokens_mistral': 3392, 'n_tokens_neox': 3221, 'n_words': 824}