-
Notifications
You must be signed in to change notification settings - Fork 11
use cobra command for llcppg #582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tsingbx
wants to merge
9
commits into
xgo-dev:main
Choose a base branch
from
tsingbx:cpp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8a397d4
add outline for use cobra command for llcppg
tsingbx 9a8e25e
implement gencfg sub command
tsingbx c0fc2d0
implement sub command for gensym
tsingbx 2cad0a2
implement sub command for gensig
tsingbx f1938d8
implement genpkg sub command
tsingbx c0e13b4
rename new llcppg command to llcppgx
tsingbx 45caad9
remove version sub command
tsingbx bda7808
delete default completion sub command
tsingbx fb56e76
check -mod flag and fix type error
tsingbx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * Copyright (c) 2023 The GoPlus Authors (goplus.org). All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| // Package base defines shared basic pieces of the llgo command, | ||
| // in particular logging and the Command structure. | ||
| package base | ||
|
|
||
| import ( | ||
| "flag" | ||
| "fmt" | ||
| "io" | ||
| "strings" | ||
| ) | ||
|
|
||
| // A Command is an implementation of a xgo command | ||
| // like xgo export or xgo install. | ||
| type Command struct { | ||
| // Run runs the command. | ||
| // The args are the arguments after the command name. | ||
| Run func(cmd *Command, args []string) | ||
|
|
||
| // UsageLine is the one-line usage message. | ||
| // The words between "gop" and the first flag or argument in the line are taken to be the command name. | ||
|
tsingbx marked this conversation as resolved.
Outdated
|
||
| UsageLine string | ||
|
|
||
| // Short is the short description shown in the 'gop help' output. | ||
| Short string | ||
|
|
||
| // Flag is a set of flags specific to this command. | ||
| Flag flag.FlagSet | ||
|
|
||
| // Commands lists the available commands and help topics. | ||
| // The order here is the order in which they are printed by 'gop help'. | ||
| // Note that subcommands are in general best avoided. | ||
| Commands []*Command | ||
| } | ||
|
tsingbx marked this conversation as resolved.
Outdated
|
||
|
|
||
| // Llcppg command | ||
| var Llcppg = &Command{ | ||
| UsageLine: "llcppg", | ||
| Short: `llcppg aims to be a tool for automatically generating LLGo bindings for C/C++ libraries, enhancing the experience of integrating LLGo with C!`, | ||
| // Commands initialized in package main | ||
| } | ||
|
|
||
| // LongName returns the command's long name: all the words in the usage line between "gop" and a flag or argument, | ||
|
tsingbx marked this conversation as resolved.
Outdated
|
||
| func (c *Command) LongName() string { | ||
| name := c.UsageLine | ||
| if i := strings.Index(name, " ["); i >= 0 { | ||
| name = name[:i] | ||
| } | ||
| if name == "llcppg" { | ||
| return "" | ||
| } | ||
| return strings.TrimPrefix(name, "llcppg ") | ||
| } | ||
|
|
||
| // Name returns the command's short name: the last word in the usage line before a flag or argument. | ||
| func (c *Command) Name() string { | ||
| name := c.LongName() | ||
| if i := strings.LastIndex(name, " "); i >= 0 { | ||
| name = name[i+1:] | ||
| } | ||
| return name | ||
| } | ||
|
|
||
| // Usage show the command usage. | ||
| func (c *Command) Usage(w io.Writer) { | ||
| fmt.Fprintf(w, "%s\n\nUsage: %s\n", c.Short, c.UsageLine) | ||
|
|
||
| // restore output of flag | ||
| defer c.Flag.SetOutput(c.Flag.Output()) | ||
|
|
||
| c.Flag.SetOutput(w) | ||
| c.Flag.PrintDefaults() | ||
| fmt.Fprintln(w) | ||
| } | ||
|
|
||
| // Runnable reports whether the command can be run; otherwise | ||
| // it is a documentation pseudo-command. | ||
| func (c *Command) Runnable() bool { | ||
| return c.Run != nil | ||
| } | ||
|
|
||
| // Usage is the usage-reporting function, filled in by package main | ||
| // but here for reference by other packages. | ||
| // | ||
| // flag.Usage func() | ||
|
|
||
| // CmdName - "build", "install", "list", "mod tidy", etc. | ||
| var CmdName string | ||
|
|
||
| // Main runs a command. | ||
| func Main(c *Command, app string, args []string) { | ||
| name := c.UsageLine | ||
| if i := strings.Index(name, " ["); i >= 0 { | ||
| c.UsageLine = app + name[i:] | ||
| } | ||
| c.Run(c, args) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package base | ||
|
|
||
| import ( | ||
| "flag" | ||
| "fmt" | ||
| "strings" | ||
| ) | ||
|
|
||
| type stringValue struct { | ||
| p *PassArgs | ||
| name string | ||
| } | ||
|
|
||
| func (p *stringValue) String() string { | ||
| return "" | ||
| } | ||
|
|
||
| func (p *stringValue) Set(v string) error { | ||
| p.p.Args = append(p.p.Args, fmt.Sprintf("-%v=%v", p.name, v)) | ||
|
tsingbx marked this conversation as resolved.
Outdated
|
||
| return nil | ||
| } | ||
|
|
||
| type boolValue struct { | ||
| p *PassArgs | ||
| name string | ||
| } | ||
|
|
||
| func (p *boolValue) String() string { | ||
| return "" | ||
| } | ||
|
|
||
| func (p *boolValue) Set(v string) error { | ||
| p.p.Args = append(p.p.Args, fmt.Sprintf("-%v=%v", p.name, v)) | ||
| return nil | ||
| } | ||
|
|
||
| func (p *boolValue) IsBoolFlag() bool { | ||
| return true | ||
| } | ||
|
|
||
| type PassArgs struct { | ||
| Args []string | ||
| Flag *flag.FlagSet | ||
| } | ||
|
|
||
| func (p *PassArgs) Tags() string { | ||
| for _, v := range p.Args { | ||
| if strings.HasPrefix(v, "-tags=") { | ||
| return v[6:] | ||
| } | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| func (p *PassArgs) Var(names ...string) { | ||
| for _, name := range names { | ||
| p.Flag.Var(&stringValue{p: p, name: name}, name, "") | ||
| } | ||
| } | ||
|
|
||
| func (p *PassArgs) Bool(names ...string) { | ||
| for _, name := range names { | ||
| p.Flag.Var(&boolValue{p: p, name: name}, name, "") | ||
| } | ||
| } | ||
|
|
||
| func NewPassArgs(flag *flag.FlagSet) *PassArgs { | ||
| p := &PassArgs{Flag: flag} | ||
|
tsingbx marked this conversation as resolved.
Outdated
|
||
| return p | ||
| } | ||
|
|
||
| func PassBuildFlags(cmd *Command) *PassArgs { | ||
| p := NewPassArgs(&cmd.Flag) | ||
| p.Bool("n", "x") | ||
| p.Bool("a") | ||
| p.Bool("linkshared", "race", "msan", "asan", | ||
| "trimpath", "work") | ||
| p.Var("p", "asmflags", "compiler", | ||
| "gcflags", "gccgoflags", "installsuffix", | ||
| "ldflags", "pkgdir", "toolexec", "buildvcs") | ||
| return p | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package gencfg | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/goplus/llcppg/cmd/internal/base" | ||
| ) | ||
|
|
||
| var Cmd = &base.Command{ | ||
| UsageLine: "llcppg gencfg", | ||
| Short: "generate llcpp.cfg", | ||
|
tsingbx marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| func init() { | ||
| Cmd.Run = runCmd | ||
| } | ||
|
|
||
| func runCmd(cmd *base.Command, args []string) { | ||
| fmt.Printf("todo generate llcpp.cfg") | ||
|
tsingbx marked this conversation as resolved.
Outdated
|
||
| } | ||
|
tsingbx marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package genpkg | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/goplus/llcppg/cmd/internal/base" | ||
| ) | ||
|
|
||
| var Cmd = &base.Command{ | ||
| UsageLine: "llcppg genpkg", | ||
| Short: "generate a go package by signature information of symbols", | ||
| } | ||
|
|
||
| func init() { | ||
| Cmd.Run = runCmd | ||
| } | ||
|
|
||
| func runCmd(cmd *base.Command, args []string) { | ||
| fmt.Printf("todo genpkg") | ||
| } | ||
|
tsingbx marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package gensig | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/goplus/llcppg/cmd/internal/base" | ||
| ) | ||
|
|
||
| var Cmd = &base.Command{ | ||
| UsageLine: "llcppg gensig", | ||
| Short: "generate signature information of C/C++ symbols", | ||
| } | ||
|
|
||
| func init() { | ||
| Cmd.Run = runCmd | ||
| } | ||
|
|
||
| func runCmd(cmd *base.Command, args []string) { | ||
| fmt.Printf("todo gensig") | ||
| } | ||
|
tsingbx marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package gensym | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/goplus/llcppg/cmd/internal/base" | ||
| ) | ||
|
|
||
| var Cmd = &base.Command{ | ||
| UsageLine: "llcppg gensym", | ||
| Short: "generate symbol table for a C/C++ library", | ||
| } | ||
|
|
||
| func init() { | ||
| Cmd.Run = runCmd | ||
| } | ||
|
|
||
| func runCmd(cmd *base.Command, args []string) { | ||
| fmt.Printf("todo gensym") | ||
| } | ||
|
tsingbx marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package runtest | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/goplus/llcppg/cmd/internal/base" | ||
| ) | ||
|
|
||
| var Cmd = &base.Command{ | ||
| UsageLine: "llcppg runtest", | ||
| Short: "run test for llcppg", | ||
| } | ||
|
|
||
| func init() { | ||
| Cmd.Run = runCmd | ||
| } | ||
|
|
||
| func runCmd(cmd *base.Command, args []string) { | ||
| fmt.Printf("todo runtest") | ||
| } | ||
|
tsingbx marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package version | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/goplus/llcppg/cmd/internal/base" | ||
| ) | ||
|
|
||
| var Cmd = &base.Command{ | ||
| UsageLine: "llcppg version", | ||
| Short: "Print llcppg version", | ||
| } | ||
|
|
||
| func init() { | ||
| Cmd.Run = runCmd | ||
| } | ||
|
|
||
| func runCmd(cmd *base.Command, args []string) { | ||
| fmt.Printf("todo print version") | ||
| } | ||
|
tsingbx marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import ( | ||
| self "github.com/goplus/llcppg/cmd/internal/gencfg" | ||
| ) | ||
|
|
||
| use "gencfg" | ||
|
|
||
| short "generate llcpp.cfg" | ||
|
|
||
| run args => { | ||
| self.Cmd.Run self.Cmd, args | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import ( | ||
| self "github.com/goplus/llcppg/cmd/internal/genpkg" | ||
| ) | ||
|
|
||
| use "genpkg" | ||
|
|
||
| short "generate a go package by signature information of symbols" | ||
|
|
||
| run args => { | ||
| self.Cmd.Run self.Cmd, args | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import ( | ||
| self "github.com/goplus/llcppg/cmd/internal/gensig" | ||
| ) | ||
|
|
||
| use "gensig" | ||
|
|
||
| short "generate signature information of C/C++ symbols" | ||
|
|
||
| run args => { | ||
| self.Cmd.Run self.Cmd, args | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import ( | ||
| self "github.com/goplus/llcppg/cmd/internal/gensym" | ||
| ) | ||
|
|
||
| use "gensym" | ||
|
|
||
| short "generate symbol table for a C/C++ library" | ||
|
|
||
| run args => { | ||
| self.Cmd.Run self.Cmd, args | ||
| } |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| short `llcppg aims to be a tool for automatically generating LLGo bindings for C/C++ libraries, enhancing the experience of integrating LLGo with C!` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import ( | ||
| self "github.com/goplus/llcppg/cmd/internal/runtest" | ||
| ) | ||
|
|
||
| use "runtest" | ||
|
|
||
| short "run test for llcppg" | ||
|
|
||
| run args => { | ||
| self.Cmd.Run self.Cmd, args | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import ( | ||
| self "github.com/goplus/llcppg/cmd/internal/version" | ||
| ) | ||
|
|
||
| use "version" | ||
|
|
||
| short "Print llcppg version" | ||
|
|
||
| run args => { | ||
| self.Cmd.Run self.Cmd, args | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.