Browse Source

add basic CLI for package

master
ojizero 2 years ago
parent
commit
74d30d05c6
  1. 34
      cmd/main.go
  2. 1
      go.mod
  3. 2
      go.sum

34
cmd/main.go

@ -0,0 +1,34 @@ @@ -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
go.mod

@ -4,5 +4,6 @@ go 1.13 @@ -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
go.sum

@ -4,6 +4,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb @@ -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