ln implemented.
This commit is contained in:
parent
5140f3591b
commit
afa0e736bd
6 changed files with 120 additions and 67 deletions
|
@ -7,6 +7,7 @@ install-sh:VQ: build
|
|||
fi
|
||||
if test -d app ; then
|
||||
echo Installing application files...
|
||||
echo "'$APPDIR'"
|
||||
mkdir -p $APPDIR/$PKG_NAME && cp -rf app/* $APPDIR/$PKG_NAME/
|
||||
echo Done installing application files
|
||||
fi
|
||||
|
|
|
@ -1,35 +1,36 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
mtool "github.com/surdeus/gomtool/src/multitool"
|
||||
"github.com/surdeus/goblin/src/tool/awk"
|
||||
"github.com/surdeus/goblin/src/tool/basename"
|
||||
"github.com/surdeus/goblin/src/tool/cat"
|
||||
"github.com/surdeus/goblin/src/tool/date"
|
||||
"github.com/surdeus/goblin/src/tool/ec"
|
||||
"github.com/surdeus/goblin/src/tool/echo"
|
||||
"github.com/surdeus/goblin/src/tool/mkdir"
|
||||
"github.com/surdeus/goblin/src/tool/gtrue"
|
||||
"github.com/surdeus/goblin/src/tool/ftest"
|
||||
"github.com/surdeus/goblin/src/tool/gfalse"
|
||||
"github.com/surdeus/goblin/src/tool/grange"
|
||||
"github.com/surdeus/goblin/src/tool/gtrue"
|
||||
"github.com/surdeus/goblin/src/tool/in"
|
||||
"github.com/surdeus/goblin/src/tool/ln"
|
||||
"github.com/surdeus/goblin/src/tool/ls"
|
||||
"github.com/surdeus/goblin/src/tool/mergelbl"
|
||||
"github.com/surdeus/goblin/src/tool/mk"
|
||||
"github.com/surdeus/goblin/src/tool/mkdir"
|
||||
"github.com/surdeus/goblin/src/tool/noext"
|
||||
"github.com/surdeus/goblin/src/tool/path"
|
||||
"github.com/surdeus/goblin/src/tool/paths"
|
||||
"github.com/surdeus/goblin/src/tool/quote"
|
||||
"github.com/surdeus/goblin/src/tool/read"
|
||||
"github.com/surdeus/goblin/src/tool/sort"
|
||||
"github.com/surdeus/goblin/src/tool/tac"
|
||||
"github.com/surdeus/goblin/src/tool/ls"
|
||||
"github.com/surdeus/goblin/src/tool/yes"
|
||||
"github.com/surdeus/goblin/src/tool/date"
|
||||
"github.com/surdeus/goblin/src/tool/uniq"
|
||||
"github.com/surdeus/goblin/src/tool/quote"
|
||||
"github.com/surdeus/goblin/src/tool/urlprs"
|
||||
"github.com/surdeus/goblin/src/tool/noext"
|
||||
"github.com/surdeus/goblin/src/tool/mergelbl"
|
||||
"github.com/surdeus/goblin/src/tool/basename"
|
||||
"github.com/surdeus/goblin/src/tool/ec"
|
||||
"github.com/surdeus/goblin/src/tool/read"
|
||||
"github.com/surdeus/goblin/src/tool/wc"
|
||||
"github.com/surdeus/goblin/src/tool/ftest"
|
||||
"github.com/surdeus/goblin/src/tool/grange"
|
||||
"github.com/surdeus/goblin/src/tool/in"
|
||||
"github.com/surdeus/goblin/src/tool/useprog"
|
||||
"github.com/surdeus/goblin/src/tool/path"
|
||||
"github.com/surdeus/goblin/src/tool/mk"
|
||||
"github.com/surdeus/goblin/src/tool/awk"
|
||||
"github.com/surdeus/goblin/src/tool/paths"
|
||||
"github.com/surdeus/goblin/src/tool/wc"
|
||||
"github.com/surdeus/goblin/src/tool/whoami"
|
||||
"github.com/surdeus/goblin/src/tool/yes"
|
||||
mtool "github.com/surdeus/gomtool/src/multitool"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -68,6 +69,10 @@ func main() {
|
|||
whoami.Run,
|
||||
"print current user name",
|
||||
},
|
||||
"ln": mtool.Tool{
|
||||
ln.Run,
|
||||
"link files",
|
||||
},
|
||||
}
|
||||
|
||||
mtool.Main("goblin", tools)
|
||||
|
|
|
@ -4,8 +4,8 @@ package pathx
|
|||
// paths.
|
||||
|
||||
import (
|
||||
fp "path/filepath"
|
||||
"path"
|
||||
fp "path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -28,10 +28,10 @@ func From(p string) Path {
|
|||
return ret
|
||||
}
|
||||
|
||||
p = path.Clean(p)
|
||||
/* p = path.Clean(p)
|
||||
if p[0] == '/' {
|
||||
ret.IsAbs = true
|
||||
}
|
||||
} */
|
||||
p, _ = strings.CutSuffix(p, "/")
|
||||
svalues := strings.Split(p, "/")
|
||||
|
||||
|
@ -44,6 +44,10 @@ func From(p string) Path {
|
|||
return ret
|
||||
}
|
||||
|
||||
func FromReal(p string) Path {
|
||||
return From(fp.ToSlash(p))
|
||||
}
|
||||
|
||||
func (v Value) IsValid() bool {
|
||||
return v.Err() == nil
|
||||
}
|
||||
|
@ -66,11 +70,17 @@ func (p Path) StringValues() []string {
|
|||
}
|
||||
|
||||
func (p Path) Real() string {
|
||||
return fp.Join(p.StringValues()...)
|
||||
return strings.Join(p.StringValues(), string(fp.Separator))
|
||||
}
|
||||
|
||||
func (p Path) String() string {
|
||||
return path.Join(p.StringValues()...)
|
||||
ret := ""
|
||||
if p.IsAbs {
|
||||
ret = "/"
|
||||
}
|
||||
|
||||
ret += path.Join(p.StringValues()...)
|
||||
return ret
|
||||
}
|
||||
|
||||
func (p Path) IsValid() bool {
|
||||
|
@ -92,4 +102,3 @@ func (p Path) Err() error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
35
src/tool/ln/main.go
Normal file
35
src/tool/ln/main.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package ln
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func Run(args []string) {
|
||||
var lflag bool
|
||||
flagSet := flag.NewFlagSet(args[0], flag.ExitOnError)
|
||||
flagSet.BoolVar(&lflag, "s", false, "make a symbolic link, not a hard one")
|
||||
|
||||
flagSet.Parse(args[1:])
|
||||
args = flagSet.Args()
|
||||
|
||||
if len(args) != 2 {
|
||||
flagSet.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
src := args[0]
|
||||
dst := args[1]
|
||||
|
||||
var err error
|
||||
if lflag {
|
||||
err = os.Symlink(src, dst)
|
||||
} else {
|
||||
err = os.Link(src, dst)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/surdeus/goblin/src/pathx"
|
||||
)
|
||||
|
||||
|
@ -93,7 +94,6 @@ const (
|
|||
)
|
||||
|
||||
// Build a node's prereqs. Block until completed.
|
||||
//
|
||||
func mkNodePrereqs(g *graph, u *node, e *edge, prereqs []*node, dryrun bool,
|
||||
required bool) nodeStatus {
|
||||
prereqstat := make(chan nodeStatus)
|
||||
|
@ -131,11 +131,11 @@ func mkNodePrereqs(g *graph, u *node, e *edge, prereqs []*node, dryrun bool,
|
|||
// concurrently.
|
||||
//
|
||||
// Args:
|
||||
//
|
||||
// g: Graph in which the node lives.
|
||||
// u: Node to (possibly) build.
|
||||
// dryrun: Don't actually build anything, just pretend.
|
||||
// required: Avoid building this node, unless its prereqs are out of date.
|
||||
//
|
||||
func mkNode(g *graph, u *node, dryrun bool, required bool) {
|
||||
// try to claim on this node
|
||||
u.mutex.Lock()
|
||||
|
@ -327,9 +327,9 @@ func Run(args []string) {
|
|||
arg0 := args[0]
|
||||
args = args[1:]
|
||||
|
||||
if mkincdir := os.Getenv("MKINCDIR") ;
|
||||
mkincdir == "" {
|
||||
if mkincdir := os.Getenv("MKINCDIR"); mkincdir == "" {
|
||||
homeDir, _ := os.UserHomeDir()
|
||||
homeDir = pathx.FromReal(homeDir).String()
|
||||
os.Setenv("MKINCDIR", homeDir+"/app/goblin/mk/inc")
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/surdeus/goblin/src/pathx"
|
||||
)
|
||||
|
||||
|
@ -169,9 +170,11 @@ func parseRedirInclude(p *parser, t token) parserStateFun {
|
|||
true,
|
||||
)[0]
|
||||
}
|
||||
file, err := os.Open(pathx.From(filename).Real())
|
||||
pths := pathx.From(filename)
|
||||
file, err := os.Open(pths.Real())
|
||||
if err != nil {
|
||||
p.basicWarnAtToken(fmt.Sprintf("cannot open %s", filename), p.tokenbuf[0])
|
||||
//fmt.Printf("%q %q %q\n", pths.Values, pths.Real(), pths.String())
|
||||
//p.basicErrorAtToken(fmt.Sprintf("cannot open %s", filename), p.tokenbuf[0])
|
||||
}
|
||||
input, _ := io.ReadAll(file)
|
||||
|
|
Loading…
Reference in a new issue