mirror of
https://github.com/facundoolano/jorge.git
synced 2024-09-29 17:37:40 +02:00
b3594be86c
* use kong for cli parsing * fix kong usage * remove conditional * don't blow up serve if src dir is missing * load config in main side (boilerplaty) * fix weird names * add versions and aliases * fix version printing * replace command switch with Run methods * move subcommand structs to commands package * distribute commands into files * add usage to docs * add flags to configure server
48 lines
935 B
Go
48 lines
935 B
Go
package commands
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/alecthomas/kong"
|
|
"github.com/facundoolano/jorge/config"
|
|
"github.com/facundoolano/jorge/site"
|
|
)
|
|
|
|
const FILE_RW_MODE = 0777
|
|
|
|
type Build struct {
|
|
ProjectDir string `arg:"" name:"path" optional:"" default:"." help:"Path to the website project to build."`
|
|
}
|
|
|
|
// Read the files in src/ render them and copy the result to target/
|
|
func (cmd *Build) Run(ctx *kong.Context) error {
|
|
config, err := config.Load(cmd.ProjectDir)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
site, err := site.Load(*config)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return site.Build()
|
|
}
|
|
|
|
// Prompt the user for a string value
|
|
func Prompt(label string) string {
|
|
// https://dev.to/tidalcloud/interactive-cli-prompts-in-go-3bj9
|
|
var s string
|
|
r := bufio.NewReader(os.Stdin)
|
|
for {
|
|
fmt.Fprint(os.Stderr, label+": ")
|
|
s, _ = r.ReadString('\n')
|
|
if s != "" {
|
|
break
|
|
}
|
|
}
|
|
return strings.TrimSpace(s)
|
|
}
|