func main() {
	index := structs.NewIndex()
	for {
		fmt.Println("Enter command (e.g. 'help') and arguments.")
		var userInput string
		_, err := fmt.Scan(&userInput)
		if err != nil {
			if err == io.EOF {
				return
			} else {
				fmt.Println(err.Error())
			}
		} else {
			if handleCommand(userInput, index) {
				return
			}
		}
	}
}
func main() {
	var outputFileName string
	flag.StringVar(&outputFileName, "o", "", "File name to write index to.")
	flag.Parse()

	if len(outputFileName) == 0 {
		fmt.Fprintf(os.Stderr, "Output file not specified. Use -o option.\n")
		return
	}

	outputFile, err := os.Create(outputFileName)
	if err != nil {
		reportError(err)
		return
	}

	fileNames := make([]string, 0)
	for {
		var fileName string
		_, err := fmt.Scan(&fileName)
		if err != nil {
			if err != io.EOF {
				reportError(err)
			}
			break
		}
		fileNames = append(fileNames, fileName)
	}

	index := structs.NewIndex()
	crawl(index, fileNames)

	if err = saveIndex(index, outputFile); err != nil {
		reportError(err)
	}
}