gitforgefs/main.go

50 lines
1.3 KiB
Go
Raw Normal View History

2020-12-26 19:36:09 +00:00
package main
2020-12-27 03:30:19 +00:00
import (
"flag"
"fmt"
2020-12-29 02:37:18 +00:00
"net/url"
2020-12-27 03:30:19 +00:00
"os"
"github.com/badjware/gitlabfs/fs"
2020-12-29 02:37:18 +00:00
"github.com/badjware/gitlabfs/git"
2020-12-27 03:30:19 +00:00
"github.com/badjware/gitlabfs/gitlab"
)
2020-12-26 19:36:09 +00:00
func main() {
2020-12-27 03:30:19 +00:00
gitlabURL := flag.String("gitlab-url", "https://gitlab.com", "the gitlab url")
gitlabToken := flag.String("gitlab-token", "", "the gitlab authentication token")
gitlabRootGroupID := flag.Int("gitlab-group-id", 9970, "the group id of the groups at the root of the filesystem")
// gitlabNamespace := flag.String()
flag.Parse()
if flag.NArg() != 1 {
fmt.Printf("usage: %s MOUNTPOINT\n", os.Args[0])
os.Exit(2)
2020-12-27 03:30:19 +00:00
}
mountpoint := flag.Arg(0)
2020-12-29 02:37:18 +00:00
parsedGitlabURL, err := url.Parse(*gitlabURL)
if err != nil {
fmt.Printf("%v is not a valid url: %v\n", *gitlabURL, err)
os.Exit(1)
}
2020-12-27 03:30:19 +00:00
2020-12-29 02:37:18 +00:00
// Create the gitlab client
gitlabClientParam := gitlab.GitlabClientParam{}
gitlabClient, _ := gitlab.NewClient(*gitlabURL, *gitlabToken, gitlabClientParam)
2020-12-29 02:37:18 +00:00
// Create the git client
gitClientParam := git.GitClientParam{
RemoteURL: parsedGitlabURL,
AutoClone: true,
AutoPull: false,
Fetch: false,
Checkout: false,
SingleBranch: true,
PullDepth: 0,
}
gitClient, _ := git.NewClient(gitClientParam)
2020-12-29 02:37:18 +00:00
// Start the filesystem
2020-12-30 00:49:11 +00:00
fs.Start(mountpoint, []int{*gitlabRootGroupID}, []int{}, &fs.FSParam{Gitlab: gitlabClient, Git: gitClient})
2020-12-26 19:36:09 +00:00
}