<commit_before>package main

//
//
// This application can be compiled and deployed as a stand alone executable to
// create very basic bags from the commandline.
//
//

import (
	"flag"
	"fmt"
	"github.com/APTrust/bagins"
	"github.com/APTrust/bagins/bagutil"
	// "os"
	"time"
)

var (
	dir     string
	name    string
	payload string
	algo    string
)

func init() {
	flag.StringVar(&dir, "dir", "", "Directory to create the bag.")
	flag.StringVar(&name, "name", "", "Name for the bag root directory.")
	flag.StringVar(&payload, "payload", "", "Directory of files to parse into the bag")
	flag.StringVar(&algo, "algo", "md5", "Checksum algorithm to use.  md5, sha1, sha224, sha256, sha512, sha384")

	flag.Parse()
}

func usage() {

	usage := `Usage:
	./bagmaker -dir <value> -name <value> -payload <value> [-algo <value>]

Flags:

	-algo <value> Checksum algorithm to use.  md5, sha1, sha224, sha256, 
	              sha512, or sha384. Defaults to md5.

	-dir <value> Directory to create the bag.

	-name <value> Name for the bag root directory.

	-payload <value> Directory of files to parse into the bag.

`
	fmt.Println(usage)
}

func main() {

	if dir == "" {
		usage()
		return
	}
	if name == "" {
		usage()
		return
	}
	if payload == "" {
		usage()
		return
	}

	begin := time.Now()

	cs, err := bagutil.NewCheckByName(algo)
	if err != nil {
		fmt.Println("Unable to find checksum", algo)
		return
	}

	bag, err := bagins.NewBag(dir, name, cs)
	if err != nil {
		fmt.Println("Bag Error:", err)
		return
	}

	errs := bag.AddDir(payload)
	for idx := range errs {
		fmt.Println("AddDir Error:", errs[idx])
		return
	}

	// if info := parse_info(os.Args); len(info) > 0 {
	// 	bag.AddTagfile("bag-info.txt")
	// 	if tf, err := bag.BagInfo(); err != nil {
	// 		tf.Data = info
	// 	}
	// }

	bag.Close()

	elapsed := time.Since(begin)<commit_msg>Fixed naming errors in bagmaker.<commit_after>package main

//
//
// This application can be compiled and deployed as a stand alone executable to
// create very basic bags from the commandline.
//
//

import (
	"flag"
	"fmt"
	"github.com/APTrust/bagins"
	"time"
)

var (
	dir     string
	name    string
	payload string
	algo    string
)

func init() {
	flag.StringVar(&dir, "dir", "", "Directory to create the bag.")
	flag.StringVar(&name, "name", "", "Name for the bag root directory.")
	flag.StringVar(&payload, "payload", "", "Directory of files to parse into the bag")
	flag.StringVar(&algo, "algo", "md5", "Checksum algorithm to use.  md5, sha1, sha224, sha256, sha512, sha384")

	flag.Parse()
}

func usage() {

	usage := `Usage:
	./bagmaker -dir <value> -name <value> -payload <value> [-algo <value>]

Flags:

	-algo <value> Checksum algorithm to use.  md5, sha1, sha224, sha256, 
	              sha512, or sha384. Defaults to md5.

	-dir <value> Directory to create the bag.

	-name <value> Name for the bag root directory.

	-payload <value> Directory of files to copy into the bag.

`
	fmt.Println(usage)
}

func main() {

	if dir == "" {
		usage()
		return
	}
	if name == "" {
		usage()
		return
	}
	if payload == "" {
		usage()
		return
	}

	begin := time.Now()

	bag, err := bagins.NewBag(dir, name, algo)
	if err != nil {
		fmt.Println("Bag Error:", err)
		return
	}

	errs := bag.AddDir(payload)
	for idx := range errs {
		fmt.Println("AddDir Error:", errs[idx])
		return
	}

	bag.Save()

	elapsed := time.Since(begin)
{'fraction_non_alphanumeric': 0.15498373262348417, 'fraction_numerical': 0.018041999408459037, 'mean_word_length': 3.0551558752997603, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 20, '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': '767970', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1228, 'n_words': 379}