Skip to content

Commit a7b73c0

Browse files
committed
implement gencfg sub command
1 parent 8a397d4 commit a7b73c0

13 files changed

Lines changed: 66 additions & 249 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*.so
99
*.dylib
1010
*.DS_Store
11+
*_autogen.go
1112

1213
# Test binary, built with `go test -c`
1314
*.test

cmd/internal/base/base.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ type Command struct {
3333
Run func(cmd *Command, args []string)
3434

3535
// UsageLine is the one-line usage message.
36-
// The words between "gop" and the first flag or argument in the line are taken to be the command name.
36+
// The words between "llcppg" and the first flag or argument in the line are taken to be the command name.
3737
UsageLine string
3838

39-
// Short is the short description shown in the 'gop help' output.
39+
// Short is the short description shown in the 'llcppg help' output.
4040
Short string
4141

4242
// Flag is a set of flags specific to this command.
4343
Flag flag.FlagSet
4444

4545
// Commands lists the available commands and help topics.
46-
// The order here is the order in which they are printed by 'gop help'.
46+
// The order here is the order in which they are printed by 'llcppg help'.
4747
// Note that subcommands are in general best avoided.
4848
Commands []*Command
4949
}
@@ -55,7 +55,7 @@ var Llcppg = &Command{
5555
// Commands initialized in package main
5656
}
5757

58-
// LongName returns the command's long name: all the words in the usage line between "gop" and a flag or argument,
58+
// LongName returns the command's long name: all the words in the usage line between "llcppg" and a flag or argument,
5959
func (c *Command) LongName() string {
6060
name := c.UsageLine
6161
if i := strings.Index(name, " ["); i >= 0 {

cmd/internal/base/pass.go

Lines changed: 0 additions & 82 deletions
This file was deleted.

cmd/internal/gencfg/flags.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package gencfg
2+
3+
import "flag"
4+
5+
var dependencies string
6+
var extsString string
7+
var excludes string
8+
var cpp, help, tab bool
9+
10+
func addFlags(fs *flag.FlagSet) {
11+
fs.BoolVar(&cpp, "cpp", false, "if it is C++ lib")
12+
fs.BoolVar(&help, "help", false, "print help message")
13+
fs.BoolVar(&tab, "tab", true, "generate .cfg config file with tab indent")
14+
fs.StringVar(&excludes, "excludes", "", "exclude all header files in subdir of include expamle -excludes=\"internal impl\"")
15+
fs.StringVar(&extsString, "exts", ".h", "extra include file extensions for example -exts=\".h .hpp .hh\"")
16+
fs.StringVar(&dependencies, "deps", "", "deps for autofilling dependencies")
17+
}

cmd/internal/gencfg/gencfg.go

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package gencfg
22

33
import (
4-
"fmt"
4+
"os"
5+
"strings"
56

67
"github.com/goplus/llcppg/cmd/internal/base"
8+
"github.com/goplus/llcppg/cmd/llcppcfg/gen"
79
)
810

911
var Cmd = &base.Command{
@@ -13,8 +15,41 @@ var Cmd = &base.Command{
1315

1416
func init() {
1517
Cmd.Run = runCmd
18+
addFlags(&Cmd.Flag)
1619
}
1720

1821
func runCmd(cmd *base.Command, args []string) {
19-
fmt.Printf("todo generate llcpp.cfg")
22+
23+
if err := cmd.Flag.Parse(args); err != nil {
24+
return
25+
}
26+
27+
name := ""
28+
if len(cmd.Flag.Args()) > 0 {
29+
name = cmd.Flag.Arg(0)
30+
}
31+
32+
exts := strings.Fields(extsString)
33+
deps := strings.Fields(dependencies)
34+
35+
excludeSubdirs := []string{}
36+
if len(excludes) > 0 {
37+
excludeSubdirs = strings.Fields(excludes)
38+
}
39+
var flagMode gen.FlagMode
40+
if cpp {
41+
flagMode |= gen.WithCpp
42+
}
43+
if tab {
44+
flagMode |= gen.WithTab
45+
}
46+
buf, err := gen.Do(gen.NewConfig(name, flagMode, exts, deps, excludeSubdirs))
47+
if err != nil {
48+
panic(err)
49+
}
50+
outFile := "./llcppg.cfg"
51+
err = os.WriteFile(outFile, buf, 0600)
52+
if err != nil {
53+
panic(err)
54+
}
2055
}

cmd/internal/genpkg/genpkg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ func init() {
1616
}
1717

1818
func runCmd(cmd *base.Command, args []string) {
19-
fmt.Printf("todo genpkg")
19+
fmt.Println("todo genpkg")
2020
}

cmd/internal/gensig/gensig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ func init() {
1616
}
1717

1818
func runCmd(cmd *base.Command, args []string) {
19-
fmt.Printf("todo gensig")
19+
fmt.Println("todo gensig")
2020
}

cmd/internal/gensym/gensym.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ func init() {
1616
}
1717

1818
func runCmd(cmd *base.Command, args []string) {
19-
fmt.Printf("todo gensym")
19+
fmt.Println("todo gensym")
2020
}

cmd/internal/runtest/runtest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ func init() {
1616
}
1717

1818
func runCmd(cmd *base.Command, args []string) {
19-
fmt.Printf("todo runtest")
19+
fmt.Println("todo runtest")
2020
}

cmd/internal/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ func init() {
1616
}
1717

1818
func runCmd(cmd *base.Command, args []string) {
19-
fmt.Printf("todo print version")
19+
fmt.Println("todo print version")
2020
}

0 commit comments

Comments
 (0)