Handle translation specification.
This commit is contained in:
parent
324d0a2c07
commit
0b829bd30d
1 changed files with 17 additions and 21 deletions
|
|
@ -23,24 +23,21 @@ type verse struct {
|
|||
|
||||
func (m *verse) AddVerse(ctx context.Context, cmd *cli.Command) error {
|
||||
logger := logging.Get("commands")
|
||||
logger.SetFormat("verse add: {{message}}")
|
||||
logger.SetFormat("{{message}}")
|
||||
logger.SetLevel(logging.Info)
|
||||
tn := strings.ToLower(cmd.String("translation"))
|
||||
|
||||
switch tn {
|
||||
case "bsb":
|
||||
logger.Info("using translation: BSB")
|
||||
case "kjv":
|
||||
logger.Info("using translation: KJV")
|
||||
default:
|
||||
logger.Warning("invalid translation:", tn)
|
||||
return nil
|
||||
}
|
||||
|
||||
tnfs := m.fs.Clone()
|
||||
if err := tnfs.Chdir("data"); err != nil {
|
||||
return err
|
||||
}
|
||||
tns, err := bible.LoadTranslations(tnfs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if tn == "" || !tns.HasTranslation(tn) {
|
||||
tn = tns.Default
|
||||
}
|
||||
|
||||
ref, err := bible.ParseRef(strings.Join(cmd.Args().Slice(), " "))
|
||||
if err != nil {
|
||||
|
|
@ -55,10 +52,11 @@ func (m *verse) AddVerse(ctx context.Context, cmd *cli.Command) error {
|
|||
|
||||
mdl := models.NewVerseModel(ctx, mdb.DB())
|
||||
vd := &models.Verse{
|
||||
Book: ref.Book,
|
||||
Chapter: ref.Chapter,
|
||||
VerseStart: ref.Verses.Start,
|
||||
VerseStop: ref.Verses.Stop,
|
||||
Translation: tn,
|
||||
Book: ref.Book,
|
||||
Chapter: ref.Chapter,
|
||||
VerseStart: ref.Verses.Start,
|
||||
VerseStop: ref.Verses.Stop,
|
||||
}
|
||||
|
||||
txn, err := bible.LoadTranslations(tnfs)
|
||||
|
|
@ -77,11 +75,9 @@ func (m *verse) AddVerse(ctx context.Context, cmd *cli.Command) error {
|
|||
|
||||
vv.SkipLineBreaks = true
|
||||
vv.IncludeVerseNum = false
|
||||
fmt.Println("This will add the following passage:")
|
||||
|
||||
fmt.Println("")
|
||||
fmt.Printf("%s:\n", ref)
|
||||
fmt.Println(vv.String())
|
||||
logger.Info("This will add the following passage:\n")
|
||||
logger.Infof("%s:\n", ref)
|
||||
logger.Info(vv.String())
|
||||
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
fmt.Print("\nIs this okay? [y/N] ")
|
||||
|
|
@ -96,7 +92,7 @@ func (m *verse) AddVerse(ctx context.Context, cmd *cli.Command) error {
|
|||
logger.Error("failed adding verse:", errors.Unfurl(err))
|
||||
return err
|
||||
}
|
||||
logger.Info("added", ref)
|
||||
logger.Info("\nadded:", ref)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue