77 lines
1.6 KiB
Go
77 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
tpl "lamium/template"
|
|
)
|
|
|
|
var (
|
|
// App information.
|
|
app = struct {
|
|
name string
|
|
cmd string
|
|
desc string
|
|
version string
|
|
configPath string
|
|
}{
|
|
name: "Lamium",
|
|
cmd: "lm",
|
|
desc: "Static web album generator",
|
|
version: "0.1.0",
|
|
configPath: "lamium.json",
|
|
}
|
|
|
|
// Command line menu options.
|
|
helpOpts = [][]string{
|
|
{"Usage: " + app.cmd + " [option]\n"},
|
|
{"Options:"},
|
|
{"-h", "help", "Show this help message"},
|
|
{"-m", "make", "Make album in the configured directory"},
|
|
{"-n", "new", "Place a new config in the current directory"},
|
|
{"-v", "version", "Show app version"},
|
|
}
|
|
)
|
|
|
|
// Prints a help message to standard output.
|
|
func showHelp() {
|
|
for i := range helpOpts {
|
|
if len(helpOpts[i]) >= 3 {
|
|
fmt.Println(helpOpts[i][0]+", "+helpOpts[i][1], "\t\t"+
|
|
helpOpts[i][2])
|
|
} else {
|
|
fmt.Println(helpOpts[i][0])
|
|
}
|
|
}
|
|
}
|
|
|
|
// Prints version information.
|
|
func showVersion() {
|
|
fmt.Println(app.name, app.version, "—", app.desc)
|
|
}
|
|
|
|
// Maps command line options to corresponding functions.
|
|
func parseArgs(args []string) {
|
|
if len(args) > 1 {
|
|
switch args[1] {
|
|
case "-h", "h", "help":
|
|
showHelp()
|
|
case "-m", "m", "make":
|
|
conf := loadConfig(app.configPath)
|
|
index := map[string]string{
|
|
"html": conf.IndexHTML,
|
|
"type": conf.IndexType,
|
|
"title": conf.IndexTitle,
|
|
}
|
|
tpl.MakeAlbum(conf.ThemeDir, conf.HTMLDir, index, conf.Sets)
|
|
case "-n", "n", "new":
|
|
genConfig(app.configPath)
|
|
tpl.GenTheme(false)
|
|
case "-v", "v", "version":
|
|
showVersion()
|
|
}
|
|
} else {
|
|
showHelp()
|
|
}
|
|
}
|