Skip to content

Commit

Permalink
modify printHelp
Browse files Browse the repository at this point in the history
  • Loading branch information
tsingbx committed Dec 8, 2024
1 parent 3816bc3 commit 885f684
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 6 additions & 10 deletions cmd/llcppcfg/llcppcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,20 @@ import (
)

func printHelp() {
flag.Usage()
fmt.Println(`llcppcfg is to generate llcpp.cfg file.
usage: llcppcfg [-cpp|-help|-expand] libname`)
flag.PrintDefaults()
}

func main() {
var cpp bool = false
var help bool = false
var expand bool = false
var cpp, help, expand bool
flag.BoolVar(&cpp, "cpp", false, "if it is c++ lib")
flag.BoolVar(&help, "help", false, "print help message")
flag.BoolVar(&expand, "expand", false, "expand pkg-config command to result")
flag.Usage = func() {
fmt.Println(`llcppcfg is to generate llcpp.cfg file.
usage: llcppcfg [-cpp|-help|-expand] libname`)
}
flag.Usage = printHelp
flag.Parse()
if help || len(os.Args) <= 1 {
printHelp()
flag.Usage()
return
}
name := ""
Expand All @@ -39,7 +35,7 @@ usage: llcppcfg [-cpp|-help|-expand] libname`)
log.Fatal(err)
}
outFile := "./llcppg.cfg"
err = os.WriteFile(outFile, buf.Bytes(), 0644)
err = os.WriteFile(outFile, buf.Bytes(), 0600)
if err != nil {
log.Fatal(err)
}
Expand Down
10 changes: 7 additions & 3 deletions cmd/llcppcfg/llcppgcfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io/fs"
"log"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -38,7 +39,7 @@ func ExpandString(str string) string {
str = strings.ReplaceAll(str, ")", "}")
expandStr := os.Expand(str, func(s string) string {
args := strings.Fields(s)
if len(args) <= 0 {
if len(args) == 0 {
return ""
}
outString, err := CmdOutString(exec.Command(args[0], args[1:]...))
Expand All @@ -58,7 +59,7 @@ func doExpandCflags(str string, fn func(s string) bool) (includes []string, flag
for _, l := range list {
trimStr := strings.TrimPrefix(l, "-I")
trimStr += "/"
filepath.WalkDir(trimStr, func(path string, d fs.DirEntry, err error) error {
err := filepath.WalkDir(trimStr, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
Expand All @@ -79,6 +80,9 @@ func doExpandCflags(str string, fn func(s string) bool) (includes []string, flag
}
return nil
})
if err != nil {
log.Println(err)
}
}

includeMap := make(map[string]struct{})
Expand Down Expand Up @@ -144,7 +148,7 @@ func NewLLCppConfig(name string, isCpp bool, expand bool) *LLCppConfig {
}

func GenCfg(name string, cpp bool, expand bool) (*bytes.Buffer, error) {
if len(name) <= 0 {
if len(name) == 0 {
return nil, fmt.Errorf("name can't be empty")
}
cfg := NewLLCppConfig(name, cpp, expand)
Expand Down

0 comments on commit 885f684

Please sign in to comment.