2021-10-30 23:25:44 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-11-17 00:19:46 +00:00
|
|
|
// "accorder/pkg/calibre"
|
2021-10-30 23:25:44 +00:00
|
|
|
"github.com/spf13/cobra"
|
2021-11-17 00:19:46 +00:00
|
|
|
"github.com/spf13/viper"
|
2021-10-30 23:25:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var buildCmd = &cobra.Command{
|
|
|
|
Use: "build",
|
|
|
|
Short: "Build standalone, portable webapp from Calibre library.",
|
|
|
|
Long: `Build searchable, standalone, portable webapp against the local Calibre
|
|
|
|
library including all the metadata needed. It creates BROWSE_LIBRARY.html in
|
|
|
|
root directory of the local Calibre library. For search (authors, titles,
|
|
|
|
tags...) it uses rendered metadata from static/data{1-8}.js files.
|
|
|
|
|
|
|
|
Every time the directory path and/or librarian is provided it is saved in
|
|
|
|
the configuration file for the future use (therefore: 'accorder build PROFILE'
|
|
|
|
should be enough for the next successful build).`,
|
|
|
|
Args: OnlyProfileArgument,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2021-11-17 00:19:46 +00:00
|
|
|
fromFlag := viper.GetString("directory")
|
|
|
|
fromConfig := viper.GetString(fmt.Sprintf("%s.directory", args[0]))
|
|
|
|
if fromFlag != "" && fromFlag != fromConfig {
|
|
|
|
fmt.Printf("Would you like to write the new directory path:\n%s\ninto the configuration file?\n", viper.GetString("directory"))
|
|
|
|
fromConfig = fromFlag
|
|
|
|
}
|
|
|
|
fmt.Println("DIRECTORY:", fromConfig)
|
|
|
|
// calibre.RenderStandaloneApp()
|
2021-10-30 23:25:44 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
buildCmd.PersistentFlags().StringP("directory", "d", "", "A local Calibre directory path.")
|
|
|
|
buildCmd.PersistentFlags().StringP("librarian", "l", "", "Librarian's name.")
|
|
|
|
buildCmd.PersistentFlags().StringP("jsonpath", "j", "", "Path where to render all metadata into JSON.")
|
|
|
|
buildCmd.PersistentFlags().StringP("bibtex", "b", "", "Import books from BibTex file into Calibre.")
|
|
|
|
CustomHelpOutput(buildCmd)
|
2021-11-17 00:19:46 +00:00
|
|
|
viper.BindPFlag("directory", buildCmd.PersistentFlags().Lookup("directory"))
|
|
|
|
rootCmd.AddCommand(buildCmd)
|
2021-10-30 23:25:44 +00:00
|
|
|
}
|