Skip to content

Commit

Permalink
[Arch+Docs]: move cli tool so we can exec the go command
Browse files Browse the repository at this point in the history
  • Loading branch information
4lxprime committed Jun 20, 2024
1 parent 2e04094 commit 040e67b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 71 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# gitdl
git downloader for specific folder
git downloader for specific folder

you can use it like this in your code:
## cli:
you can run the cli with `go run github.com/4lxprime/gitdl -h` from anywhere on your system as long as you have go installed.

## code:
```golang
if err := gitdl.DownloadGit(
"torvalds/linux", // base the clone on https://github.com/torvalds/linux
Expand All @@ -10,9 +13,10 @@ if err := gitdl.DownloadGit(
gitdl.WithBranch("master"), // base the clone on the master branch (default main)
gitdl.WithExclusions("configs/*", "async.c"), // exclude everything in configs/ and exclude async.c
gitdl.WithReplace(gitdl.Map{"linux", "linuxisbetter"}) // everytime "linux" is mentionned, it will be remplaced by "linuxisbetter"
gitdl.WithLogs, // you want to enable log
gitdl.WithAuth("ghp_*") // use your github auth token so you can have likely unlimited requests
gitdl.WithoutChecksum // don't care about security (not recommended)
); err != nil {
log.Fatal(err)
}
```

or you can just use the cli tool with `go run cmd/gitdl/main.go -repo=torvalds/linux -folder=kernel -output=linux_kernel -logs` but there is no every options.
64 changes: 64 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package main

import (
"flag"
"fmt"
"log"
"strings"
)

func main() {
repoFlag := flag.String("repo", "", "[required] the repo you want to download folder from")
folderFlag := flag.String("folder", "/", "[optional] folder you want to download from repo")
branchFlag := flag.String("branch", "main", "[optional] the branch you want to clone")
authFlag := flag.String("auth", "", "[optional] your github auth token")
outputFlag := flag.String("output", "", "[optional] local output folder")
logsFlag := flag.Bool("logs", true, "[optional] display downloading logs")
noChecksumFlag := flag.Bool("nochecksum", false, "[optional] disable downloading checksum")

flag.Parse()

if *repoFlag == "" {
log.Fatal(fmt.Errorf("you should specify the repo you want to clone (e.g. gitdl -folder=/ -output=gitdl 4lxprime/gitdl)"))
}

if !strings.Contains(*repoFlag, "/") {
log.Fatal(fmt.Errorf("repo argument must contains / (e.g. 4lxprime/gitdl or github.com/4lxprime/gitdl)"))
}

if *outputFlag == "" {
repoSplit := strings.Split(*repoFlag, "/")
repoName := repoSplit[len(repoSplit)-1]

*outputFlag = repoName
}

var options []Option

if *logsFlag {
options = append(options, WithLogs)
}

if *noChecksumFlag {
options = append(options, WithoutChecksum)
}

if *authFlag != "" {
options = append(options, WithAuth(*authFlag))
}

options = append(options, WithBranch(*branchFlag)) // default set to main

if err := DownloadGit(
*repoFlag,
*folderFlag,
*outputFlag,
options...,
); err != nil {
log.Fatal(err)
}

if *logsFlag {
log.Println("download completed successfully")
}
}
66 changes: 0 additions & 66 deletions cmd/gitdl/main.go

This file was deleted.

2 changes: 1 addition & 1 deletion gitdl.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gitdl
package main

import (
"bytes"
Expand Down

0 comments on commit 040e67b

Please sign in to comment.