mirror of
https://github.com/danog/gojekyll.git
synced 2024-11-26 21:34:45 +01:00
106 lines
2.1 KiB
Go
106 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
. "github.com/osteele/gojekyll/helpers"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
_ "gopkg.in/urfave/cli.v1"
|
|
)
|
|
|
|
// Command-line options
|
|
var options struct {
|
|
useHardLinks bool
|
|
dryRun bool
|
|
}
|
|
|
|
// This is the longest label. Pull it out here so we can both use it, and measure it for alignment.
|
|
const configurationFileLabel = "Configuration file:"
|
|
|
|
func printSetting(label string, value string) {
|
|
fmt.Printf("%s %s\n", LeftPad(label, len(configurationFileLabel)), value)
|
|
}
|
|
|
|
func printPathSetting(label string, path string) {
|
|
path, err := filepath.Abs(path)
|
|
if err != nil {
|
|
panic("Couldn't convert to absolute path")
|
|
}
|
|
printSetting(label, path)
|
|
}
|
|
|
|
func main() {
|
|
var source, destination string
|
|
|
|
app := cli.NewApp()
|
|
app.Name = "gojekyll"
|
|
app.Usage = "a (maybe someday) Jekyll-compatible blog generator in Go"
|
|
|
|
app.Flags = []cli.Flag{
|
|
cli.StringFlag{
|
|
Name: "source",
|
|
Value: ".",
|
|
Usage: "Source directory",
|
|
Destination: &source,
|
|
},
|
|
cli.StringFlag{
|
|
Name: "destination",
|
|
Value: "",
|
|
Usage: "Destination directory",
|
|
Destination: &destination,
|
|
},
|
|
}
|
|
|
|
withSite := func(cmd func(*cli.Context, *Site) error) func(*cli.Context) error {
|
|
siteLoader := func() error { return loadSite(source, destination) }
|
|
return loadSiteAndRun(siteLoader, cmd)
|
|
}
|
|
|
|
app.Commands = []cli.Command{
|
|
{
|
|
Name: "server",
|
|
Aliases: []string{"s", "serve"},
|
|
Usage: "Serve your site locally",
|
|
Action: withSite(serveCommand),
|
|
},
|
|
{
|
|
Name: "build",
|
|
Aliases: []string{"b"},
|
|
Usage: "Build your site",
|
|
Flags: []cli.Flag{
|
|
cli.BoolFlag{
|
|
Name: "dry-run, n",
|
|
Usage: "Dry run",
|
|
Destination: &options.dryRun,
|
|
},
|
|
},
|
|
Action: withSite(buildCommand),
|
|
},
|
|
{
|
|
Name: "data",
|
|
Aliases: []string{"b"},
|
|
Action: withSite(dataCommand),
|
|
},
|
|
{
|
|
Name: "routes",
|
|
Flags: []cli.Flag{
|
|
cli.BoolFlag{
|
|
Name: "dynamic",
|
|
Usage: "Only show routes to non-static files",
|
|
},
|
|
},
|
|
Action: withSite(routesCommand),
|
|
},
|
|
{
|
|
Name: "render",
|
|
Action: withSite(renderCommand),
|
|
},
|
|
}
|
|
|
|
_ = app.Run(os.Args)
|
|
}
|