Go implementation of the original bash plugin, containing all features
This commit is contained in:
parent
7061cf1f1d
commit
1ec3bbb482
19 changed files with 826 additions and 671 deletions
116
cmd/drone-hugo/main.go
Normal file
116
cmd/drone-hugo/main.go
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/drone-plugins/drone-hugo"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var build = "0" // build number set at compile-time
|
||||
var version = "2.0"
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "hugo plugin"
|
||||
app.Usage = "hugo plugin"
|
||||
app.Action = run
|
||||
app.Version = fmt.Sprintf("%s build %s", version, build)
|
||||
app.Flags = []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "buildDrafts",
|
||||
Usage: " include content marked as draft",
|
||||
EnvVar: "PLUGIN_BUILDDRAFTS",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "buildExpired",
|
||||
Usage: "include expired content",
|
||||
EnvVar: "PLUGIN_BUILDEXPIRED",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "buildFuture",
|
||||
Usage: "include content with publishdate in the future",
|
||||
EnvVar: "PLUGIN_BUILDFUTURE",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "config",
|
||||
Usage: "config file (default is path/config.yaml|json|toml)",
|
||||
EnvVar: "PLUGIN_CONFIG",
|
||||
Value: "",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "content",
|
||||
Usage: "filesystem path to content directory",
|
||||
EnvVar: "PLUGIN_CONTENT",
|
||||
Value: "",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "layout",
|
||||
Usage: "filesystem path to layout directory",
|
||||
EnvVar: "PLUGIN_LAYOUT",
|
||||
Value: "",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "output",
|
||||
Usage: "filesystem path to write files to",
|
||||
EnvVar: "PLUGIN_OUTPUT",
|
||||
Value: "",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "source",
|
||||
Usage: "filesystem path to read files relative from",
|
||||
EnvVar: "PLUGIN_SOURCE",
|
||||
Value: "",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "theme",
|
||||
Usage: "theme to use (located in /themes/THEMENAME/)",
|
||||
EnvVar: "PLUGIN_THEME",
|
||||
Value: "",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "url",
|
||||
Usage: "hostname (and path) to the root",
|
||||
EnvVar: "PLUGIN_URL",
|
||||
Value: "",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "validate",
|
||||
Usage: "validate config file before generation",
|
||||
EnvVar: "PLUGIN_VALIDATE",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "hugoVersion",
|
||||
Usage: "the hugo version to be used",
|
||||
EnvVar: "PLUGIN_HUGO_VERSION",
|
||||
Value: "",
|
||||
},
|
||||
}
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func run(c *cli.Context) error {
|
||||
plugin := hugo.Plugin{
|
||||
Config: hugo.Config{
|
||||
HugoVersion: c.String("hugoVersion"),
|
||||
BuildDrafts: c.Bool("buildDrafts"),
|
||||
BuildExpired: c.Bool("buildExpired"),
|
||||
BuildFuture: c.Bool("buildFuture"),
|
||||
Validate: c.Bool("validate"),
|
||||
Config: c.String("config"),
|
||||
Content: c.String("content"),
|
||||
Layout: c.String("layout"),
|
||||
Output: c.String("output"),
|
||||
Source: c.String("source"),
|
||||
Theme: c.String("theme"),
|
||||
Url: c.String("url"),
|
||||
},
|
||||
Architecture: os.Getenv("PLUGIN_HUGO_ARCH"),
|
||||
BuildInVersion: os.Getenv("PLUGIN_HUGO_SHIPPED_VERSION"),
|
||||
}
|
||||
return plugin.Exec()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue