Browse Source

add basic CLI for package

tags/v1.1.0
ojizero 4 months ago
parent
commit
74d30d05c6
3 changed files with 37 additions and 0 deletions
  1. 34
    0
      cmd/main.go
  2. 1
    0
      go.mod
  3. 2
    0
      go.sum

+ 34
- 0
cmd/main.go View File

@@ -0,0 +1,34 @@
package main

import (
"fmt"

flag "github.com/spf13/pflag"

"github.com/ojizero/gofindup"
)

func main() {
var (
startdir string
nametofind string
)

flag.StringVarP(&startdir, "startdir", "s", "", "Directory to start searching from, if not given would search from current working directory")
flag.Parse()
nametofind = flag.Arg(0)

findup := gofindup.Findup
if startdir != "" {
findup = func(name string) (string, error) {
return gofindup.FindupFrom(name, startdir)
}
}

found, err := findup(nametofind)
if err != nil {
panic(err)
}

fmt.Print(found)
}

+ 1
- 0
go.mod View File

@@ -4,5 +4,6 @@ go 1.13

require (
github.com/spf13/afero v1.2.2
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.4.0
)

+ 2
- 0
go.sum View File

@@ -4,6 +4,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=

Loading…
Cancel
Save