<commit_before>package flenv

import (
	"errors"
	"flag"
	"net/url"
	"os"
	"reflect"
	"strconv"
	"strings"
	"time"
)

var ErrNotStruct = errors.New("Attempted to decode into a value that was not a pointer to struct")
var ErrUnsupportedFlagType = errors.New("Unsupported flag type")

func DecodeArgs(result interface{}) (*flag.FlagSet, error) {
	return Decode(result, os.Args)
}

func Decode(result interface{}, args []string) (*flag.FlagSet, error) {
	flagSet := flag.NewFlagSet("", flag.ContinueOnError)

	val := reflect.ValueOf(result)
	if val.Kind() != reflect.Ptr {
		return nil, ErrNotStruct
	}

	st := val.Elem()
	if st.Kind() != reflect.Struct {
		return nil, ErrNotStruct
	}
<commit_msg>Add documentation to Decode<commit_after>package flenv

import (
	"errors"
	"flag"
	"net/url"
	"os"
	"reflect"
	"strconv"
	"strings"
	"time"
)

// ErrNotStruct is an error
var ErrNotStruct = errors.New("Attempted to decode into a value that was not a pointer to struct")

// ErrNotStruct is an error
var ErrUnsupportedFlagType = errors.New("Unsupported flag type")

// DecodeArgs runs decode with os.Args
func DecodeArgs(result interface{}) (*flag.FlagSet, error) {
	return Decode(result, os.Args)
}

// Decode attempts to populate result, based on struct tags from args and the environment
//
// `result` should be a struct with at least one of the following tags
//
//    env:"ENVIRONMENT_VARIABLE"
//    flag:"--environment-variable"
//
// Additionally, the following tags are also allowed
//
//    help:"help text for flag parsing"
//    default:"default value"
func Decode(result interface{}, args []string) (*flag.FlagSet, error) {
	flagSet := flag.NewFlagSet("", flag.ContinueOnError)

	val := reflect.ValueOf(result)
	if val.Kind() != reflect.Ptr {
		return nil, ErrNotStruct
	}

	st := val.Elem()
	if st.Kind() != reflect.Struct {
		return nil, ErrNotStruct
	}

{'fraction_non_alphanumeric': 0.1319034852546917, 'fraction_numerical': 0.0, 'mean_word_length': 4.1689750692520775, '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': '386335', 'n_tokens_mistral': 627, 'n_tokens_neox': 616, 'n_words': 189}