I will save this but will probably change this
This commit is contained in:
64
main.go
64
main.go
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user