<commit_before>package hush // import "github.com/mndrix/hush"

import (
	"fmt"
	"os"
)

// Main implements the main() function of the hush command line tool.
func Main() {
	if os.Args[1] == "init" {
		err := CmdInit(os.Stderr, os.Stdin)
		if err != nil {
			die("%s", err.Error())
		}
		return
	}

	tree, err := LoadTree()
	if os.IsNotExist(err) {
		filename, _ := HushPath()
		fmt.Fprintf(os.Stderr, "hush file does not exist: %s\n", filename)
		fmt.Fprintf(os.Stderr, "Maybe you need to run 'hush init'?\n")
		os.Exit(1)
	}
	if err != nil {
		die("%s", err.Error())
	}

	// prepare for encryption and decryption
	err = setPassphrase(tree)
	if err != nil {
		die("%s", err.Error())
	}

	// handle most commands
	switch os.Args[1] {
	case "export": // hush export
		err = CmdExport(os.Stdout, tree)
	case "import": // hush import
		var warnings []string
		warnings, err = CmdImport(os.Stdin, tree)
		for _, warning := range warnings {
			warn(warning)
		}
	case "ls": // hush ls foo/bar
		if len(os.Args) < 3 {
			tree.Print(os.Stdout)
			return
		}
		err = CmdLs(os.Stdout, tree, os.Args[2])
	case "rm": // hush rm paypal.com/personal
		paths := make([]Path, len(os.Args)-2)
		for i := 2; i < len(os.Args); i++ {
			paths[i-2] = NewPath(os.Args[i])
		}
		err = CmdRm(tree, paths)
	case "set": // hush set paypal.com/personal/user <EMAIL>
		p := NewPath(os.Args[2])
		v, err := CaptureValue(os.Args[3])
		if err != nil {
			die("%s", err.Error())
		}
		err = CmdSet(os.Stdout, tree, p, v)
	default:
		die("Usage: hush ...")
	}
	if err != nil {
		die("%s", err.Error())
	}
}

func setPassphrase(t *Tree) error {
	password, err := AskPassword(os.Stderr, "Password")
	if err != nil {
		return err
	}

	return t.SetPassphrase(password)
}

func die(format string, args ...interface{}) {
	fmt.Fprintf(os.Stderr, format+"\n", args...)
	os.Exit(1)
}<commit_msg>Show usage when called without a command<commit_after>package hush // import "github.com/mndrix/hush"

import (
	"fmt"
	"os"
)

// Main implements the main() function of the hush command line tool.
func Main() {
	if len(os.Args) < 2 {
		usage()
		return
	}

	if os.Args[1] == "init" {
		err := CmdInit(os.Stderr, os.Stdin)
		if err != nil {
			die("%s", err.Error())
		}
		return
	}

	tree, err := LoadTree()
	if os.IsNotExist(err) {
		filename, _ := HushPath()
		fmt.Fprintf(os.Stderr, "hush file does not exist: %s\n", filename)
		fmt.Fprintf(os.Stderr, "Maybe you need to run 'hush init'?\n")
		os.Exit(1)
	}
	if err != nil {
		die("%s", err.Error())
	}

	// prepare for encryption and decryption
	err = setPassphrase(tree)
	if err != nil {
		die("%s", err.Error())
	}

	// handle most commands
	switch os.Args[1] {
	case "export": // hush export
		err = CmdExport(os.Stdout, tree)
	case "import": // hush import
		var warnings []string
		warnings, err = CmdImport(os.Stdin, tree)
		for _, warning := range warnings {
			warn(warning)
		}
	case "ls": // hush ls foo/bar
		if len(os.Args) < 3 {
			tree.Print(os.Stdout)
			return
		}
		err = CmdLs(os.Stdout, tree, os.Args[2])
	case "rm": // hush rm paypal.com/personal
		paths := make([]Path, len(os.Args)-2)
		for i := 2; i < len(os.Args); i++ {
			paths[i-2] = NewPath(os.Args[i])
		}
		err = CmdRm(tree, paths)
	case "set": // hush set paypal.com/personal/user <EMAIL>
		p := NewPath(os.Args[2])
		v, err := CaptureValue(os.Args[3])
		if err != nil {
			die("%s", err.Error())
		}
		err = CmdSet(os.Stdout, tree, p, v)
	default:
		usage()
	}
	if err != nil {
		die("%s", err.Error())
	}
}

func usage() {
	die("Usage: hush [command [arguments]]")
}

func setPassphrase(t *Tree) error {
	password, err := AskPassword(os.Stderr, "Password")
	if err != nil {
		return err
	}

	return t.SetPassphrase(password)
}

func die(format string, args ...interface{}) {
	fmt.Fprintf(os.Stderr, format+"\n", args...)
	os.Exit(1)
}
{'fraction_non_alphanumeric': 0.18374281233664402, 'fraction_numerical': 0.0060115002613695765, 'mean_word_length': 3.159782608695652, 'pattern_counts': {'":': 10, '<': 10, '<?xml version=': 0, '>': 5, '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': '6209608', 'n_tokens_mistral': 1640, 'n_tokens_neox': 1533, 'n_words': 390}