generating "," instead of keeping it in repository
This commit is contained in:
31
main.go
31
main.go
@@ -1,10 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
var commaSh = `#!/bin/sh
|
||||
|
||||
script_path=$(realpath $0)
|
||||
script_dir=$(dirname $script_path)
|
||||
|
||||
cd $script_dir
|
||||
|
||||
output=/tmp/commandgo
|
||||
|
||||
# why not just using "go run ." ?
|
||||
# Because "go run ." will inject GOBIN into PATH while compiling,
|
||||
# and modifed PATH will pass into actual program.
|
||||
# So the program doesn't have the same PATH as outside.
|
||||
# It's not a acceptable behavior.
|
||||
|
||||
go build -o $output . && $output $@
|
||||
`
|
||||
|
||||
func commandsUsage() string {
|
||||
return fmt.Sprintf(
|
||||
`commands:
|
||||
@@ -13,6 +32,18 @@ func commandsUsage() string {
|
||||
}
|
||||
|
||||
func main() {
|
||||
pwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("detect current directory failed! %w", err))
|
||||
}
|
||||
target := pwd + string(os.PathSeparator) + ","
|
||||
_, err = os.Stat(target)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
err := os.WriteFile(target, []byte(commaSh), 0755)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("write sh failed: %w", err))
|
||||
}
|
||||
}
|
||||
if len(os.Args) >= 2 {
|
||||
switch os.Args[1] {
|
||||
case "path":
|
||||
|
||||
Reference in New Issue
Block a user