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 {
|
func (m *verse) AddVerse(ctx context.Context, cmd *cli.Command) error {
|
||||||
logger := logging.Get("commands")
|
logger := logging.Get("commands")
|
||||||
logger.SetFormat("verse add: {{message}}")
|
logger.SetFormat("{{message}}")
|
||||||
logger.SetLevel(logging.Info)
|
logger.SetLevel(logging.Info)
|
||||||
tn := strings.ToLower(cmd.String("translation"))
|
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()
|
tnfs := m.fs.Clone()
|
||||||
if err := tnfs.Chdir("data"); err != nil {
|
if err := tnfs.Chdir("data"); err != nil {
|
||||||
return err
|
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(), " "))
|
ref, err := bible.ParseRef(strings.Join(cmd.Args().Slice(), " "))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -55,10 +52,11 @@ func (m *verse) AddVerse(ctx context.Context, cmd *cli.Command) error {
|
||||||
|
|
||||||
mdl := models.NewVerseModel(ctx, mdb.DB())
|
mdl := models.NewVerseModel(ctx, mdb.DB())
|
||||||
vd := &models.Verse{
|
vd := &models.Verse{
|
||||||
Book: ref.Book,
|
Translation: tn,
|
||||||
Chapter: ref.Chapter,
|
Book: ref.Book,
|
||||||
VerseStart: ref.Verses.Start,
|
Chapter: ref.Chapter,
|
||||||
VerseStop: ref.Verses.Stop,
|
VerseStart: ref.Verses.Start,
|
||||||
|
VerseStop: ref.Verses.Stop,
|
||||||
}
|
}
|
||||||
|
|
||||||
txn, err := bible.LoadTranslations(tnfs)
|
txn, err := bible.LoadTranslations(tnfs)
|
||||||
|
|
@ -77,11 +75,9 @@ func (m *verse) AddVerse(ctx context.Context, cmd *cli.Command) error {
|
||||||
|
|
||||||
vv.SkipLineBreaks = true
|
vv.SkipLineBreaks = true
|
||||||
vv.IncludeVerseNum = false
|
vv.IncludeVerseNum = false
|
||||||
fmt.Println("This will add the following passage:")
|
logger.Info("This will add the following passage:\n")
|
||||||
|
logger.Infof("%s:\n", ref)
|
||||||
fmt.Println("")
|
logger.Info(vv.String())
|
||||||
fmt.Printf("%s:\n", ref)
|
|
||||||
fmt.Println(vv.String())
|
|
||||||
|
|
||||||
scanner := bufio.NewScanner(os.Stdin)
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
fmt.Print("\nIs this okay? [y/N] ")
|
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))
|
logger.Error("failed adding verse:", errors.Unfurl(err))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logger.Info("added", ref)
|
logger.Info("\nadded:", ref)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue