комментарии и сообщения переведены на английский
- комментарии, тексты ошибок, вывод CLI и сообщения тестов теперь на английском - по-русски остались только литералы словаря ru и содержимое фикстур: это данные под проверкой, а не текст инструмента - согласование числительных в итоге упростилось до английского plural
This commit is contained in:
+30
-30
@@ -1,10 +1,10 @@
|
||||
// Package cli раскладывает команды инструмента.
|
||||
// Package cli lays out the commands of the tool.
|
||||
//
|
||||
// Глубина команды отражает частоту и адресата: проектные команды выполняются в
|
||||
// каждом репозитории и часто, ведение набора — в одном репозитории и редко.
|
||||
// Поэтому `check` стоит наверху, а под `suite` уходит то, что в проекте не
|
||||
// имеет смысла. Синонимов нет: `convy suite pull` рядом с `convy pull` не
|
||||
// заводится.
|
||||
// The depth of a command reflects how often it runs and whom it addresses:
|
||||
// project commands run in every repository and often, tending a suite runs in
|
||||
// one repository and rarely. That is why `check` stays at the top level and
|
||||
// whatever makes no sense in a project goes under `suite`. There are no
|
||||
// synonyms: `convy suite pull` is not introduced next to `convy pull`.
|
||||
package cli
|
||||
|
||||
import (
|
||||
@@ -13,19 +13,20 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// ExitCode — код возврата процесса.
|
||||
// ExitCode is the exit status of the process.
|
||||
type ExitCode int
|
||||
|
||||
const (
|
||||
// OK — проверка прошла, работа сделана.
|
||||
// OK means the check passed and the work is done.
|
||||
OK ExitCode = 0
|
||||
// Failed — проверка нашла ошибки.
|
||||
// Failed means the check found errors.
|
||||
Failed ExitCode = 1
|
||||
// Usage — команда набрана неверно или не в том контексте.
|
||||
// Usage means the command was typed wrong or run in the wrong context.
|
||||
Usage ExitCode = 2
|
||||
)
|
||||
|
||||
// Env — окружение запуска. Вынесено, чтобы команды тестировались без процесса.
|
||||
// Env is the environment of a run. It is pulled out so that commands can be
|
||||
// tested without a process.
|
||||
type Env struct {
|
||||
Dir string
|
||||
Out io.Writer
|
||||
@@ -34,7 +35,7 @@ type Env struct {
|
||||
Colors bool
|
||||
}
|
||||
|
||||
// Run разбирает аргументы и выполняет команду.
|
||||
// Run parses the arguments and executes the command.
|
||||
func Run(env Env, args []string) ExitCode {
|
||||
if len(args) == 0 {
|
||||
usage(env.Out)
|
||||
@@ -45,13 +46,13 @@ func Run(env Env, args []string) ExitCode {
|
||||
case "suite":
|
||||
return runSuite(env, args[1:])
|
||||
case "add", "pull", "list", "check":
|
||||
fmt.Fprintf(env.Err, "команда %q ещё не реализована\n", args[0])
|
||||
fmt.Fprintf(env.Err, "the %q command is not implemented yet\n", args[0])
|
||||
return Usage
|
||||
case "help", "-h", "--help":
|
||||
usage(env.Out)
|
||||
return OK
|
||||
default:
|
||||
fmt.Fprintf(env.Err, "неизвестная команда %q\n\n", args[0])
|
||||
fmt.Fprintf(env.Err, "unknown command %q\n\n", args[0])
|
||||
usage(env.Err)
|
||||
return Usage
|
||||
}
|
||||
@@ -59,44 +60,43 @@ func Run(env Env, args []string) ExitCode {
|
||||
|
||||
func runSuite(env Env, args []string) ExitCode {
|
||||
if len(args) == 0 {
|
||||
fmt.Fprintln(env.Err, "convy suite: нужна подкоманда — check")
|
||||
fmt.Fprintln(env.Err, "convy suite: a subcommand is required — check")
|
||||
return Usage
|
||||
}
|
||||
switch args[0] {
|
||||
case "check":
|
||||
return runSuiteCheck(env, args[1:])
|
||||
case "new":
|
||||
fmt.Fprintln(env.Err, "команда \"suite new\" ещё не реализована")
|
||||
fmt.Fprintln(env.Err, "the \"suite new\" command is not implemented yet")
|
||||
return Usage
|
||||
default:
|
||||
fmt.Fprintf(env.Err, "неизвестная подкоманда %q для convy suite\n", args[0])
|
||||
fmt.Fprintf(env.Err, "unknown subcommand %q for convy suite\n", args[0])
|
||||
return Usage
|
||||
}
|
||||
}
|
||||
|
||||
// usage печатает помощь, сгруппированную заголовками: в плоском списке уровни
|
||||
// не видны.
|
||||
// usage prints the help grouped under headings: a flat list hides the levels.
|
||||
func usage(w io.Writer) {
|
||||
fmt.Fprint(w, `convy — управление конвенциями разработки.
|
||||
fmt.Fprint(w, `convy — tending development conventions.
|
||||
|
||||
В проекте:
|
||||
convy add <тема> подписаться и собрать (не реализовано)
|
||||
convy pull пересобрать подписанное (не реализовано)
|
||||
convy list что подключено и что доступно (не реализовано)
|
||||
convy check проверить форму того, что здесь (не реализовано)
|
||||
In a project:
|
||||
convy add <topic> subscribe and assemble (not implemented)
|
||||
convy pull reassemble what is subscribed (not implemented)
|
||||
convy list what is wired up and available (not implemented)
|
||||
convy check check the form of what is here (not implemented)
|
||||
|
||||
В наборе:
|
||||
convy suite check целостность набора: префиксы, темы, оси, ссылки, форма
|
||||
convy suite new новая тема (не реализовано)
|
||||
In a suite:
|
||||
convy suite check suite integrity: prefixes, topics, axes, links, form
|
||||
convy suite new a new topic (not implemented)
|
||||
|
||||
`)
|
||||
}
|
||||
|
||||
// Main — точка входа процесса.
|
||||
// Main is the entry point of the process.
|
||||
func Main() int {
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "не удалось определить текущую директорию:", err)
|
||||
fmt.Fprintln(os.Stderr, "cannot determine the current directory:", err)
|
||||
return int(Usage)
|
||||
}
|
||||
env := Env{Dir: dir, Out: os.Stdout, Err: os.Stderr}
|
||||
|
||||
+16
-28
@@ -16,8 +16,8 @@ import (
|
||||
func runSuiteCheck(env Env, args []string) ExitCode {
|
||||
fs := flag.NewFlagSet("convy suite check", flag.ContinueOnError)
|
||||
fs.SetOutput(env.Err)
|
||||
root := fs.String("root", "", "корень набора; по умолчанию ищется вверх от текущей директории")
|
||||
quiet := fs.Bool("quiet", false, "печатать только находки")
|
||||
root := fs.String("root", "", "root of the suite; by default it is looked up upwards from the current directory")
|
||||
quiet := fs.Bool("quiet", false, "print findings only")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return Usage
|
||||
}
|
||||
@@ -27,9 +27,9 @@ func runSuiteCheck(env Env, args []string) ExitCode {
|
||||
found, err := manifest.Find(env.Dir)
|
||||
if err != nil {
|
||||
if errors.Is(err, manifest.ErrNotFound) {
|
||||
fmt.Fprintf(env.Err, "здесь не набор конвенций: рядом и выше нет %s\n", manifest.Name)
|
||||
fmt.Fprintf(env.Err, "not a conventions suite: no %s here or above\n", manifest.Name)
|
||||
if _, err := os.Stat(filepath.Join(env.Dir, ".conventions.toml")); err == nil {
|
||||
fmt.Fprintln(env.Err, "это проект — проверка того, что здесь, называется \"convy check\"")
|
||||
fmt.Fprintln(env.Err, "this is a project — checking what is here is called \"convy check\"")
|
||||
}
|
||||
return Usage
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func printReport(w io.Writer, rep *check.Report, s *suite.Suite, quiet bool) {
|
||||
if f.Line > 0 {
|
||||
where = fmt.Sprintf(":%d", f.Line)
|
||||
}
|
||||
fmt.Fprintf(w, " %s%s %s [%s]\n", label(f.Severity), where, f.Msg, f.Family)
|
||||
fmt.Fprintf(w, " %s%s %s [%s]\n", f.Severity, where, f.Msg, f.Family)
|
||||
}
|
||||
|
||||
if quiet {
|
||||
@@ -77,36 +77,24 @@ func printReport(w io.Writer, rep *check.Report, s *suite.Suite, quiet bool) {
|
||||
if len(findings) > 0 {
|
||||
fmt.Fprintln(w)
|
||||
}
|
||||
fmt.Fprintf(w, "набор: %s, %s, версия языка %d (%s)\n",
|
||||
plural(len(s.Docs), "файл", "файла", "файлов"),
|
||||
plural(len(s.Manifest.LiveTopics()), "тема", "темы", "тем"),
|
||||
fmt.Fprintf(w, "suite: %s, %s, language version %d (%s)\n",
|
||||
plural(len(s.Docs), "file"),
|
||||
plural(len(s.Manifest.LiveTopics()), "topic"),
|
||||
s.Manifest.Language.Version, s.Manifest.Language.Lang)
|
||||
switch {
|
||||
case rep.Errors() > 0:
|
||||
fmt.Fprintf(w, "ошибок: %d, предупреждений: %d\n", rep.Errors(), rep.Warnings())
|
||||
fmt.Fprintf(w, "errors: %d, warnings: %d\n", rep.Errors(), rep.Warnings())
|
||||
case rep.Warnings() > 0:
|
||||
fmt.Fprintf(w, "ошибок нет, предупреждений: %d\n", rep.Warnings())
|
||||
fmt.Fprintf(w, "no errors, warnings: %d\n", rep.Warnings())
|
||||
default:
|
||||
fmt.Fprintln(w, "целостность набора в порядке")
|
||||
fmt.Fprintln(w, "suite integrity holds")
|
||||
}
|
||||
}
|
||||
|
||||
// plural согласует существительное с числом: 1 файл, 2 файла, 5 файлов.
|
||||
func plural(n int, one, few, many string) string {
|
||||
word := many
|
||||
switch {
|
||||
case n%100 >= 11 && n%100 <= 14:
|
||||
case n%10 == 1:
|
||||
word = one
|
||||
case n%10 >= 2 && n%10 <= 4:
|
||||
word = few
|
||||
// plural agrees a noun with a count: 1 file, 4 files.
|
||||
func plural(n int, noun string) string {
|
||||
if n == 1 {
|
||||
return fmt.Sprintf("%d %s", n, noun)
|
||||
}
|
||||
return fmt.Sprintf("%d %s", n, word)
|
||||
}
|
||||
|
||||
func label(s check.Severity) string {
|
||||
if s == check.Warning {
|
||||
return "предупреждение"
|
||||
}
|
||||
return "ошибка"
|
||||
return fmt.Sprintf("%d %ss", n, noun)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user