Skip to content

Commit 5145e64

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

File tree

9 files changed

+53
-93
lines changed

9 files changed

+53
-93
lines changed

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/gencfg.go

Lines changed: 44 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{
@@ -16,5 +18,45 @@ func init() {
1618
}
1719

1820
func runCmd(cmd *base.Command, args []string) {
19-
fmt.Printf("todo generate llcpp.cfg")
21+
var dependencies string
22+
var cpp, help, tab bool
23+
cmd.Flag.BoolVar(&cpp, "cpp", false, "if it is C++ lib")
24+
cmd.Flag.BoolVar(&help, "help", false, "print help message")
25+
cmd.Flag.BoolVar(&tab, "tab", true, "generate .cfg config file with tab indent")
26+
extsString := ""
27+
cmd.Flag.StringVar(&extsString, "exts", ".h", "extra include file extensions for example -exts=\".h .hpp .hh\"")
28+
excludes := ""
29+
cmd.Flag.StringVar(&excludes, "excludes", "", "exclude all header files in subdir of include expamle -excludes=\"internal impl\"")
30+
cmd.Flag.StringVar(&dependencies, "deps", "", "deps for autofilling dependencies")
31+
if err := cmd.Flag.Parse(args); err != nil {
32+
return
33+
}
34+
name := ""
35+
if len(cmd.Flag.Args()) > 0 {
36+
name = cmd.Flag.Arg(0)
37+
}
38+
39+
exts := strings.Fields(extsString)
40+
deps := strings.Fields(dependencies)
41+
42+
excludeSubdirs := []string{}
43+
if len(excludes) > 0 {
44+
excludeSubdirs = strings.Fields(excludes)
45+
}
46+
var flagMode gen.FlagMode
47+
if cpp {
48+
flagMode |= gen.WithCpp
49+
}
50+
if tab {
51+
flagMode |= gen.WithTab
52+
}
53+
buf, err := gen.Do(gen.NewConfig(name, flagMode, exts, deps, excludeSubdirs))
54+
if err != nil {
55+
panic(err)
56+
}
57+
outFile := "./llcppg.cfg"
58+
err = os.WriteFile(outFile, buf, 0600)
59+
if err != nil {
60+
panic(err)
61+
}
2062
}

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
}

cmd/llcppg/llcppg

-3.4 MB
Binary file not shown.

0 commit comments

Comments
 (0)