<commit_before>package command

import (
	"flag"
	"fmt"
	"net/http"
	"strings"

	"github.com/TailorDev/msw/parser"
	"github.com/mitchellh/cli"
)

// ValidateCommand is a Command that validates a YAML file.
type ValidateCommand struct {
	UI cli.Ui
}

// Run runs the code of the comand.
func (c *ValidateCommand) Run(args []string) int {
	cmdFlags := flag.NewFlagSet("validate", flag.ContinueOnError)
	cmdFlags.Usage = func() { c.UI.Output(c.Help()) }
	if err := cmdFlags.Parse(args); err != nil {
		return 1
	}

	args = cmdFlags.Args()
	if len(args) != 1 {
		cmdFlags.Usage()
		return 1
	}

	issue, err := parser.Parse(args[0])
	if err != nil {
		c.UI.Error(fmt.Sprintf("%s", err))
		return 1
	}

	if issue.WelcomeText == "" {
		c.UI.Output("Welcome text is empty")
	}

	for _, category := range issue.Categories {
		if len(category.Links) == 0 {
			c.UI.Output(fmt.Sprintf("No link found for category '%s'", category.Title))
			continue
		}

		done := make(chan bool)
		for idx, link := range category.Links {
			if link.Name == "" {
				c.UI.Output(fmt.Sprintf(
					"No name given for link #%d in category '%s'",
					idx+1,
					category.Title,
				))
			}
			if link.URL == "" {
				c.UI.Output(fmt.Sprintf(
					"No URL given for link #%d in category '%s'",
					idx+1,
					category.Title,
				))
			} else {
				go testLinkURL(link.URL, c.UI, done)
			}
		}
		for i := 0; i < len(category.Links); i++ {
			<-done
		}
	}

	return 0
}

// Help returns the description of the command.
func (*ValidateCommand) Help() string {
	helpText := `
Usage: msw validate FILENAME

  This command checks whether a filename contains a valid issue.

`
	return strings.TrimSpace(helpText)
}

// Synopsis returns the short description of the command.
func (*ValidateCommand) Synopsis() string {
	return "check that an issue is valid"
}

func testLinkURL(url string, ui cli.Ui, done chan bool) {
	resp, err := http.Head(url)
	if err != nil {<commit_msg>Only wait for actual go routines<commit_after>package command

import (
	"flag"
	"fmt"
	"net/http"
	"strings"

	"github.com/TailorDev/msw/parser"
	"github.com/mitchellh/cli"
)

// ValidateCommand is a Command that validates a YAML file.
type ValidateCommand struct {
	UI cli.Ui
}

// Run runs the code of the comand.
func (c *ValidateCommand) Run(args []string) int {
	cmdFlags := flag.NewFlagSet("validate", flag.ContinueOnError)
	cmdFlags.Usage = func() { c.UI.Output(c.Help()) }
	if err := cmdFlags.Parse(args); err != nil {
		return 1
	}

	args = cmdFlags.Args()
	if len(args) != 1 {
		cmdFlags.Usage()
		return 1
	}

	issue, err := parser.Parse(args[0])
	if err != nil {
		c.UI.Error(fmt.Sprintf("%s", err))
		return 1
	}

	if issue.WelcomeText == "" {
		c.UI.Output("Welcome text is empty")
	}

	for _, category := range issue.Categories {
		if len(category.Links) == 0 {
			c.UI.Output(fmt.Sprintf("No link found for category '%s'", category.Title))
			continue
		}

		done := make(chan bool)
		wait := 0
		for idx, link := range category.Links {
			if link.Name == "" {
				c.UI.Output(fmt.Sprintf(
					"No name given for link #%d in category '%s'",
					idx+1,
					category.Title,
				))
			}
			if link.URL == "" {
				c.UI.Output(fmt.Sprintf(
					"No URL given for link #%d in category '%s'",
					idx+1,
					category.Title,
				))
			} else {
				wait++
				go testLinkURL(link.URL, c.UI, done)
			}
		}
		for i := 0; i < wait; i++ {
			<-done
		}
	}

	return 0
}

// Help returns the description of the command.
func (*ValidateCommand) Help() string {
	helpText := `
Usage: msw validate FILENAME

  This command checks whether a filename contains a valid issue.

`
	return strings.TrimSpace(helpText)
}

// Synopsis returns the short description of the command.
func (*ValidateCommand) Synopsis() string {
	return "check that an issue is valid"
}

func testLinkURL(url string, ui cli.Ui, done chan bool) {
	resp, err := http.Head(url)
	if err != nil {
{'fraction_non_alphanumeric': 0.14402660526989, 'fraction_numerical': 0.005372217958557176, 'mean_word_length': 3.0771637122002087, 'pattern_counts': {'":': 0, '<': 7, '<?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': '724026', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1380, 'n_words': 406}