2020-12-26 19:36:09 +00:00
|
|
|
package main
|
|
|
|
|
2020-12-27 03:30:19 +00:00
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2024-06-06 05:51:34 +00:00
|
|
|
"log/slog"
|
2020-12-27 03:30:19 +00:00
|
|
|
"os"
|
2021-08-13 17:40:26 +00:00
|
|
|
"strings"
|
2020-12-27 03:30:19 +00:00
|
|
|
|
2024-06-08 03:36:45 +00:00
|
|
|
"github.com/badjware/gitlabfs/config"
|
2024-05-05 20:23:07 +00:00
|
|
|
"github.com/badjware/gitlabfs/fstree"
|
2020-12-29 02:37:18 +00:00
|
|
|
"github.com/badjware/gitlabfs/git"
|
2024-08-04 19:44:50 +00:00
|
|
|
"github.com/badjware/gitlabfs/platforms/github"
|
2024-05-06 01:06:34 +00:00
|
|
|
"github.com/badjware/gitlabfs/platforms/gitlab"
|
2020-12-27 03:30:19 +00:00
|
|
|
)
|
2020-12-26 19:36:09 +00:00
|
|
|
|
|
|
|
func main() {
|
2021-08-13 17:40:26 +00:00
|
|
|
configPath := flag.String("config", "", "The config file")
|
|
|
|
mountoptionsFlag := flag.String("o", "", "Filesystem mount options. See mount.fuse(8)")
|
|
|
|
debug := flag.Bool("debug", false, "Enable debug logging")
|
|
|
|
|
|
|
|
flag.Usage = func() {
|
|
|
|
fmt.Println("USAGE:")
|
|
|
|
fmt.Printf(" %s MOUNTPOINT\n\n", os.Args[0])
|
|
|
|
fmt.Println("OPTIONS:")
|
|
|
|
flag.PrintDefaults()
|
|
|
|
}
|
2020-12-27 03:30:19 +00:00
|
|
|
flag.Parse()
|
2020-12-30 23:00:37 +00:00
|
|
|
|
2024-06-08 03:36:45 +00:00
|
|
|
loadedConfig, err := config.LoadConfig(*configPath)
|
2020-12-30 23:00:37 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2024-06-06 05:51:34 +00:00
|
|
|
// Get logger
|
|
|
|
logger := slog.Default()
|
|
|
|
|
2020-12-30 23:00:37 +00:00
|
|
|
// Configure mountpoint
|
2024-06-08 03:36:45 +00:00
|
|
|
mountpoint := loadedConfig.FS.Mountpoint
|
2020-12-30 23:00:37 +00:00
|
|
|
if flag.NArg() == 1 {
|
|
|
|
mountpoint = flag.Arg(0)
|
|
|
|
}
|
|
|
|
if mountpoint == "" {
|
2021-08-13 17:40:26 +00:00
|
|
|
fmt.Println("Mountpoint is not configured in config file and missing from command-line arguments")
|
|
|
|
flag.Usage()
|
2020-12-27 07:23:00 +00:00
|
|
|
os.Exit(2)
|
2020-12-27 03:30:19 +00:00
|
|
|
}
|
2020-12-30 23:00:37 +00:00
|
|
|
|
2021-08-13 17:40:26 +00:00
|
|
|
// Configure mountoptions
|
2024-06-08 03:36:45 +00:00
|
|
|
mountoptions := loadedConfig.FS.MountOptions
|
2021-08-13 17:40:26 +00:00
|
|
|
if *mountoptionsFlag != "" {
|
|
|
|
mountoptions = *mountoptionsFlag
|
|
|
|
}
|
|
|
|
parsedMountoptions := make([]string, 0)
|
|
|
|
if mountoptions != "" {
|
|
|
|
parsedMountoptions = strings.Split(mountoptions, ",")
|
|
|
|
}
|
|
|
|
|
2020-12-30 23:00:37 +00:00
|
|
|
// Create the git client
|
2024-06-08 03:36:45 +00:00
|
|
|
gitClientParam, err := config.MakeGitConfig(loadedConfig)
|
2020-12-29 02:37:18 +00:00
|
|
|
if err != nil {
|
2020-12-30 23:00:37 +00:00
|
|
|
fmt.Println(err)
|
2020-12-29 02:37:18 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
2024-06-06 05:51:34 +00:00
|
|
|
gitClient, _ := git.NewClient(logger, *gitClientParam)
|
2020-12-27 03:30:19 +00:00
|
|
|
|
2024-08-04 19:44:50 +00:00
|
|
|
var gitPlatformClient fstree.GitPlatform
|
|
|
|
if loadedConfig.FS.Platform == config.PlatformGitlab {
|
|
|
|
// Create the gitlab client
|
|
|
|
GitlabClientConfig, err := config.MakeGitlabConfig(loadedConfig)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2024-08-04 22:59:57 +00:00
|
|
|
gitPlatformClient, _ = gitlab.NewClient(logger, *GitlabClientConfig)
|
2024-08-04 19:44:50 +00:00
|
|
|
} else if loadedConfig.FS.Platform == config.PlatformGithub {
|
|
|
|
// Create the github client
|
|
|
|
GithubClientConfig, err := config.MakeGithubConfig(loadedConfig)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
gitPlatformClient, _ = github.NewClient(logger, *GithubClientConfig)
|
2020-12-29 02:37:18 +00:00
|
|
|
}
|
2020-12-27 07:23:00 +00:00
|
|
|
|
2020-12-29 02:37:18 +00:00
|
|
|
// Start the filesystem
|
2024-05-05 20:23:07 +00:00
|
|
|
err = fstree.Start(
|
2024-06-06 05:51:34 +00:00
|
|
|
logger,
|
2020-12-30 23:00:37 +00:00
|
|
|
mountpoint,
|
2021-08-13 17:40:26 +00:00
|
|
|
parsedMountoptions,
|
2024-08-04 19:44:50 +00:00
|
|
|
&fstree.FSParam{GitClient: gitClient, GitPlatform: gitPlatformClient},
|
2020-12-30 23:00:37 +00:00
|
|
|
*debug,
|
|
|
|
)
|
2021-03-03 05:25:49 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2020-12-26 19:36:09 +00:00
|
|
|
}
|