122 lines
2.7 KiB
Go
122 lines
2.7 KiB
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"errors"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/fatih/color"
|
|
|
|
"fes/modules/config"
|
|
"fes/modules/doc"
|
|
"fes/modules/lsp"
|
|
"fes/modules/new"
|
|
"fes/modules/server"
|
|
"fes/modules/version"
|
|
)
|
|
|
|
//go:embed lib/*
|
|
var lib embed.FS
|
|
|
|
//go:embed lsp/*
|
|
var lspStubs embed.FS
|
|
|
|
//go:embed index.html
|
|
var documentation string
|
|
|
|
func init() {
|
|
config.Port = flag.Int("p", 3000, "Set the server port")
|
|
config.Color = flag.Bool("no-color", false, "Disable color output")
|
|
config.Static = flag.Bool("static", false, "Render and save all pages")
|
|
config.Docker = flag.Bool("docker", false, "Create a docker project")
|
|
|
|
config.Lib = lib
|
|
config.LspStubs = lspStubs
|
|
config.Doc = documentation
|
|
}
|
|
|
|
func main() {
|
|
flag.Usage = func() {
|
|
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [options] <command> <project_dir>\n", os.Args[0])
|
|
fmt.Fprintln(flag.CommandLine.Output(), "Commands:")
|
|
fmt.Fprintln(flag.CommandLine.Output(), " new <project_dir> Create a new project")
|
|
fmt.Fprintln(flag.CommandLine.Output(), " doc Open documentation")
|
|
fmt.Fprintln(flag.CommandLine.Output(), " run <project_dir> Start the server")
|
|
fmt.Fprintln(flag.CommandLine.Output(), " lsp <sub_command> Work with Lsp")
|
|
fmt.Fprintln(flag.CommandLine.Output(), "Options:")
|
|
flag.PrintDefaults()
|
|
fmt.Fprintln(flag.CommandLine.Output(), "For bug reports, contact a developer and describe the issue. Provide the output of the `-V1` flag.")
|
|
}
|
|
|
|
showVersion := flag.Bool("version", false, "Show version and exit")
|
|
showFullVersion := flag.Bool("V1", false, "Show extended version information and exit")
|
|
|
|
flag.Parse()
|
|
|
|
if *showVersion {
|
|
version.Version()
|
|
}
|
|
|
|
if *showFullVersion {
|
|
version.FullVersion()
|
|
}
|
|
|
|
if *config.Color {
|
|
color.NoColor = true
|
|
}
|
|
|
|
args := flag.Args()
|
|
if len(args) < 1 {
|
|
flag.Usage()
|
|
os.Exit(1)
|
|
}
|
|
|
|
cmd := args[0]
|
|
var arg string
|
|
|
|
if cmd == "doc" {
|
|
if err := doc.Open(); err != nil {
|
|
fmt.Fprintln(os.Stderr, "Error:", err)
|
|
os.Exit(1)
|
|
}
|
|
os.Exit(0)
|
|
}
|
|
|
|
if len(args) < 2 {
|
|
fmt.Fprintln(os.Stderr, "Error: not enough arguments")
|
|
flag.Usage()
|
|
os.Exit(1)
|
|
}
|
|
arg = args[1]
|
|
|
|
switch cmd {
|
|
case "new":
|
|
if err := new.Project(arg); err != nil {
|
|
fmt.Fprintln(os.Stderr, "Error:", err)
|
|
os.Exit(1)
|
|
}
|
|
case "lsp":
|
|
if err := lsp.Do(arg); err != nil {
|
|
fmt.Fprintln(os.Stderr, "Error:", err)
|
|
os.Exit(1)
|
|
}
|
|
case "run":
|
|
if err := server.Start(arg); err != nil {
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
fmt.Fprintf(os.Stderr, "%s does not exist\n", arg)
|
|
fmt.Fprintf(os.Stderr, "Try: fes new %s\n", arg)
|
|
os.Exit(1)
|
|
} else {
|
|
fmt.Fprintln(os.Stderr, "Error:", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
default:
|
|
fmt.Fprintf(os.Stderr, "Unknown command: %s\n", cmd)
|
|
flag.Usage()
|
|
os.Exit(1)
|
|
}
|
|
}
|