<commit_before>package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"os"
	"strings"
)

//Licenselist holds short and long names of licenses
type Licenselist struct {
	Short string `json:"short"`
	Long  string `json:"long"`
}

//Licenseinfo holds information of licenses
type Licenseinfo struct {
	Name        string `json:"name"`
	Title       string `json:"title"`
	Category    string `json:"category"`
	Source      string `json:"source"`
	Description string `json:"description"`
	Tags        struct {
		Required  []string `json:"required"`
		Permitted []string `json:"permitted"`
		Forbidden []string `json:"forbidden"`
	} `json:"tags"`
}

func check(e error) {
	if e != nil {
		panic(e)
	}
}

func getfilepath(filename string) string {
	gopath := os.Getenv("GOPATH")
	licensethispath := gopath + "/src/github.com/hasit/licensethis/"
	filepath := licensethispath + filename

	return filepath
}

func help() {
	helptext := `licensethis - Choose an OSS license for your project with ease.

Usage:
licensethis help
licensethis list
licensethis info <license-name>
licensethis generate <license-name>

Commands:
help		Show this help text.
list		Show a list of all available OSS licenses.
info		Show more information for a license.
generate	Generate LICENSE.txt file in current folder after asking for author name.

Examples:
licensethis help		Show this help text.
licensethis info mit		Show more information for MIT license.
licensethis generate mit	Geneate MIT license text file in current directory.`

	fmt.Printf("%v\n", helptext)
}

func list() {
	listfilepath := getfilepath("licenselist.json")
	file, err1 := ioutil.ReadFile(listfilepath)
	check(err1)

	var licenselist []Licenselist
	err2 := json.Unmarshal(file, &licenselist)
	check(err2)

	fmt.Println("List of all available OSS licenses:")
	for i := range licenselist {
		fmt.Printf("%d. %v - %v\n", i, licenselist[i].Short, licenselist[i].Long)
	}
}

// !!---FUTURE---!!
// alow substrings of license names as arguments too
func info(licensename string) {
	infofilepath := getfilepath("licenseinfo.json")
	file, err1 := ioutil.ReadFile(infofilepath)
	check(err1)

	var licenseinfo []Licenseinfo
	err2 := json.Unmarshal(file, &licenseinfo)
	check(err2)

	var closelicensenames []string

	for i := range licenseinfo {
		if licenseinfo[i].Name == licensename {
			fmt.Printf("Title: %v\n", licenseinfo[i].Title)
			fmt.Printf("Category: %v\n", licenseinfo[i].Category)
			fmt.Printf("Source: %v\n", licenseinfo[i].Source)
			fmt.Printf("Description: %v\n", licenseinfo[i].Description)
			fmt.Println("Tags: ")
			fmt.Println("  Required: ")
			for r := range licenseinfo[i].Tags.Required {
				fmt.Printf("    -%v\n", licenseinfo[i].Tags.Required[r])
			}
			fmt.Println("  Permitted: ")
			for r := range licenseinfo[i].Tags.Permitted {
				fmt.Printf("    -%v\n", licenseinfo[i].Tags.Permitted[r])
			}
			fmt.Println("  Forbidden: ")
			for r := range licenseinfo[i].Tags.Forbidden {
				fmt.Printf("    -%v\n", licenseinfo[i].Tags.Forbidden[r])
			}
			return
		} else if strings.Contains(licenseinfo[i].Name, licensename) {
			closelicensenames = append(closelicensenames, licenseinfo[i].Name)
		}
	}
	if len(closelicensenames) != 0 {
		fmt.Println("Did you mean any of these?")
		for i := range closelicensenames {
			fmt.Printf("%v\n", closelicensenames[i])
		}
	} else {
		fmt.Println("No such license was found")
		fmt.Println("Type `licensethis list` for a list of available licenses")
	}
}

func generate(licensename string) {
	fmt.Println(licensename)
}

// !!---FUTURE---!!
//might have to look into a way to accept more than one license name for `info`.
func parseArgs(args []string) {
	if len(args) == 1 {
		switch args[0] {
		case "help":
			help()
		case "list":
			list()
		default:
			fmt.Println("Incorrect usage!")
			fmt.Println("Type `licensethis help` for help on proper usage.")
		}<commit_msg>FUTURE removed<commit_after>package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"os"
	"strings"
)

//Licenselist holds short and long names of licenses
type Licenselist struct {
	Short string `json:"short"`
	Long  string `json:"long"`
}

//Licenseinfo holds information of licenses
type Licenseinfo struct {
	Name        string `json:"name"`
	Title       string `json:"title"`
	Category    string `json:"category"`
	Source      string `json:"source"`
	Description string `json:"description"`
	Tags        struct {
		Required  []string `json:"required"`
		Permitted []string `json:"permitted"`
		Forbidden []string `json:"forbidden"`
	} `json:"tags"`
}

func check(e error) {
	if e != nil {
		panic(e)
	}
}

func getfilepath(filename string) string {
	gopath := os.Getenv("GOPATH")
	licensethispath := gopath + "/src/github.com/hasit/licensethis/"
	filepath := licensethispath + filename

	return filepath
}

func help() {
	helptext := `licensethis - Choose an OSS license for your project with ease.

Usage:
licensethis help
licensethis list
licensethis info <license-name>
licensethis generate <license-name>

Commands:
help		Show this help text.
list		Show a list of all available OSS licenses.
info		Show more information for a license.
generate	Generate LICENSE.txt file in current folder after asking for author name.

Examples:
licensethis help		Show this help text.
licensethis info mit		Show more information for MIT license.
licensethis generate mit	Geneate MIT license text file in current directory.`

	fmt.Printf("%v\n", helptext)
}

func list() {
	listfilepath := getfilepath("licenselist.json")
	file, err1 := ioutil.ReadFile(listfilepath)
	check(err1)

	var licenselist []Licenselist
	err2 := json.Unmarshal(file, &licenselist)
	check(err2)

	fmt.Println("List of all available OSS licenses:")
	for i := range licenselist {
		fmt.Printf("%d. %v - %v\n", i, licenselist[i].Short, licenselist[i].Long)
	}
}

func info(licensename string) {
	infofilepath := getfilepath("licenseinfo.json")
	file, err1 := ioutil.ReadFile(infofilepath)
	check(err1)

	var licenseinfo []Licenseinfo
	err2 := json.Unmarshal(file, &licenseinfo)
	check(err2)

	var closelicensenames []string

	for i := range licenseinfo {
		if licenseinfo[i].Name == licensename {
			fmt.Printf("Title: %v\n", licenseinfo[i].Title)
			fmt.Printf("Category: %v\n", licenseinfo[i].Category)
			fmt.Printf("Source: %v\n", licenseinfo[i].Source)
			fmt.Printf("Description: %v\n", licenseinfo[i].Description)
			fmt.Println("Tags: ")
			fmt.Println("  Required: ")
			for r := range licenseinfo[i].Tags.Required {
				fmt.Printf("    -%v\n", licenseinfo[i].Tags.Required[r])
			}
			fmt.Println("  Permitted: ")
			for r := range licenseinfo[i].Tags.Permitted {
				fmt.Printf("    -%v\n", licenseinfo[i].Tags.Permitted[r])
			}
			fmt.Println("  Forbidden: ")
			for r := range licenseinfo[i].Tags.Forbidden {
				fmt.Printf("    -%v\n", licenseinfo[i].Tags.Forbidden[r])
			}
			return
		} else if strings.Contains(licenseinfo[i].Name, licensename) {
			closelicensenames = append(closelicensenames, licenseinfo[i].Name)
		}
	}
	if len(closelicensenames) != 0 {
		fmt.Println("Did you mean any of these?")
		for i := range closelicensenames {
			fmt.Printf("%v\n", closelicensenames[i])
		}
	} else {
		fmt.Println("No such license was found")
		fmt.Println("Type `licensethis list` for a list of available licenses")
	}
}

func generate(licensename string) {
	fmt.Println(licensename)
}

func parseArgs(args []string) {
	if len(args) == 1 {
		switch args[0] {
		case "help":
			help()
		case "list":
			list()
		default:
			fmt.Println("Incorrect usage!")
			fmt.Println("Type `licensethis help` for help on proper usage.")
		}
{'fraction_non_alphanumeric': 0.13687261230404427, 'fraction_numerical': 0.0028981688842049796, 'mean_word_length': 4.095302013422819, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 7, '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': '294834', 'n_tokens_mistral': 2793, 'n_tokens_neox': 2624, 'n_words': 691}