<commit_before>// This file is part of *xliffer*
//
// Copyright (C) 2015, Travelping GmbH <<EMAIL>>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

package main

import (
	"flag"
	"fmt"
	"os"
	"path"
	"sort"
)

func main() {

	outFileName := flag.String("o", "-", "output file (default: \"-\"|stdout)")
	flag.Usage = usage
	flag.Parse()

	var args = flag.Args()
	if len(args) < 1 {
		flag.Usage()
		os.Exit(0)
	}

	var (
		conv  converter
		err   error
		exist bool
	)

	if conv, exist = registeredConverters[args[0]]; !exist {
		fmt.Fprintf(os.Stderr, "error: unknown command %v\n", args[0])
		flag.Usage()
		os.Exit(1)
	}

	if err = conv.ParseArgs(os.Args[0], args[1:]); err != nil {
		fmt.Fprintf(os.Stderr, "error: parsing %v\n", err)
		os.Exit(1)
	}

	var outWriter = os.Stdout
	if *outFileName != "" && *outFileName != "-" {
		outFile, err2 := os.Create(*outFileName)
		if err2 != nil {
			fmt.Fprintf(os.Stderr, "error: can't create %q: %v\n",
				*outFileName, err2)
			os.Exit(1)
		}
		defer outFile.Close()
		outWriter = outFile
	}

	if err := conv.Convert(outWriter); err != nil {
		fmt.Fprintf(os.Stderr, "error: converting %v\n", err)
	}
}

func usage() {
	fmt.Printf("%s converts to and from XLIFF files\n\n", path.Base(os.Args[0]))
	fmt.Printf("Usage: %s [-ho] <converter> [cflags]\n\n", os.Args[0])

	var converters = []string{}
	for c, _ := range registeredConverters {
		converters = append(converters, c)
	}
	sort.Strings(converters)

	fmt.Println("Available converters:\n")
	for _, c := range converters {
		fmt.Println("", c, "\t-", registeredConverters[c].Description())
	}
	fmt.Println()
	fmt.Println("Use <converter> -h to get the flags specific for the relevant converter")
	fmt.Println()

	flag.PrintDefaults()
}<commit_msg>improve printing available converters<commit_after>// This file is part of *xliffer*
//
// Copyright (C) 2015, Travelping GmbH <<EMAIL>>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

package main

import (
	"flag"
	"fmt"
	"os"
	"path"
	"sort"
)

func main() {

	outFileName := flag.String("o", "-", "output file (default: \"-\"|stdout)")
	flag.Usage = usage
	flag.Parse()

	var args = flag.Args()
	if len(args) < 1 {
		flag.Usage()
		os.Exit(0)
	}

	var (
		conv  converter
		err   error
		exist bool
	)

	if conv, exist = registeredConverters[args[0]]; !exist {
		fmt.Fprintf(os.Stderr, "error: unknown converter %v\n", args[0])
		flag.Usage()
		os.Exit(1)
	}

	if err = conv.ParseArgs(os.Args[0], args[1:]); err != nil {
		fmt.Fprintf(os.Stderr, "error: parsing %v\n", err)
		os.Exit(1)
	}

	var outWriter = os.Stdout
	if *outFileName != "" && *outFileName != "-" {
		outFile, err2 := os.Create(*outFileName)
		if err2 != nil {
			fmt.Fprintf(os.Stderr, "error: can't create %q: %v\n",
				*outFileName, err2)
			os.Exit(1)
		}
		defer outFile.Close()
		outWriter = outFile
	}

	if err := conv.Convert(outWriter); err != nil {
		fmt.Fprintf(os.Stderr, "error: converting %v\n", err)
	}
}

func usage() {

	app := path.Base(os.Args[0])

	fmt.Printf("%s converts to and from XLIFF files\n\n", app)
	fmt.Printf("Usage: %s [-ho] <converter> [cflags]\n\n", app)

	converters := []string{}
	longest := 1

	for c, _ := range registeredConverters {
		if len(c) > longest {
			longest = len(c)
		}
		converters = append(converters, c)
	}
	sort.Strings(converters)
	format := fmt.Sprintf("  %%-%ds - %%s\n", longest)

	fmt.Println("Available converters:\n")
	for _, c := range converters {
		fmt.Printf(format, c, registeredConverters[c].Description())
	}
	fmt.Println()
	fmt.Println("Use <converter> -h to get the flags specific for the relevant converter")
	fmt.Println()

	flag.PrintDefaults()
	fmt.Println()
}
{'fraction_non_alphanumeric': 0.17362858580775037, 'fraction_numerical': 0.011071967790639155, 'mean_word_length': 3.4562780269058297, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 12, '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': '1471810', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1507, 'n_words': 402}