I will save this but will probably change this

This commit is contained in:
2025-12-29 17:11:28 -05:00
parent 99c41a0d60
commit 2b2be7b4e7
6 changed files with 258 additions and 841 deletions

64
main.go
View File

@@ -11,6 +11,7 @@ import (
"fes/modules/config"
"fes/modules/doc"
"fes/modules/lsp"
"fes/modules/new"
"fes/modules/server"
"fes/modules/version"
@@ -19,6 +20,9 @@ import (
//go:embed lib/*
var lib embed.FS
//go:embed lsp/*
var lspStubs embed.FS
//go:embed index.html
var documentation string
@@ -27,20 +31,23 @@ func init() {
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.Fprintf(os.Stderr, "Commands:")
fmt.Fprintf(os.Stderr, " new <project_dir> Create a new project")
fmt.Fprintf(os.Stderr, " doc Open documentation")
fmt.Fprintf(os.Stderr, " run <project_dir> Start the server")
fmt.Fprintf(os.Stderr, "Options:")
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.Fprintf(os.Stderr, "For bug reports, contact a developer and describe the issue. Provide the output of the `-V1` flag.")
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")
@@ -67,32 +74,39 @@ func main() {
}
cmd := args[0]
var dir string
if cmd == "new" || cmd == "run" {
if len(args) < 2 {
fmt.Fprintf(os.Stderr, "Error: %s requires <project_dir>\n", cmd)
flag.Usage()
os.Exit(1)
}
dir = args[1]
}
var arg string
switch cmd {
case "new":
if err := new.Project(dir); err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
}
case "doc":
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(dir); err != nil {
if err := server.Start(arg); err != nil {
if errors.Is(err, os.ErrNotExist) {
fmt.Fprintf(os.Stderr, "%s does not exist\n", dir)
fmt.Fprintf(os.Stderr, "Try: fes new %s\n", dir)
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)