Skip to content

Commit

Permalink
up: add some compat methods on base, fix some error
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Oct 17, 2022
1 parent 5120a1f commit 7a08b24
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ func NewApp(fns ...func(app *App)) *App {

Logf(VerbCrazy, "create a new cli application, and create base ")

// init base
app.Ctx = gCtx
// init
app.base = newBase()
app.opts = newGlobalOpts()

// set a default version
// set a default value
app.Version = "1.0.0"
app.base.Ctx = gCtx

for _, fn := range fns {
fn(app)
Expand Down
9 changes: 9 additions & 0 deletions base.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ func (b *base) initHelpReplacer() {
})
}

// BinName get bin script name
func (b *base) BinName() string { return b.Ctx.binName }

// BinDir get bin script dirname
func (b *base) BinDir() string { return b.Ctx.BinDir() }

// WorkDir get work dirname
func (b *base) WorkDir() string { return b.Ctx.workDir }

// ResetData from ctx
func (b *base) ResetData() {
if b.Ctx != nil {
Expand Down
2 changes: 1 addition & 1 deletion builtin/gen_auto_complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func GenAutoComplete() *gcli.Command {

func doGen(c *gcli.Command, _ []string) (err error) {
if len(genOpts.binName) == 0 {
genOpts.binName = c.BinName()
genOpts.binName = c.Ctx.BinName()
}

genOpts.binName = strings.TrimSuffix(strings.Trim(genOpts.binName, "./"), ".exe")
Expand Down

0 comments on commit 7a08b24

Please sign in to comment.