-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* get the tran gh api, add `auth` and `gh-config` commands * bump `abdfnx/gh` version, add `gh-repo` command to `tran` * finally, add `tran sync` command to tran, add new go modules * update `tran` root command examples Co-authored-by: @abdfnx
- Loading branch information
1 parent
5675c59
commit d3d7d17
Showing
10 changed files
with
748 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
tasks: | ||
- init: go get -d ./... | ||
command: curl -fsSL https://cutt.ly/tran-cli | bash | ||
command: | | ||
brew install go-task/tap/go-task | ||
curl -fsSL https://cutt.ly/tran-cli | bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/abdfnx/gh/pkg/cmdutil" | ||
aCmd "github.com/abdfnx/gh/pkg/cmd/auth" | ||
cCmd "github.com/abdfnx/gh/pkg/cmd/gh-config" | ||
rCmd "github.com/abdfnx/gh/pkg/cmd/gh-repo" | ||
"github.com/abdfnx/gh/context" | ||
"github.com/abdfnx/gh/api" | ||
"github.com/abdfnx/gh/core/ghrepo" | ||
) | ||
|
||
func Auth(f *cmdutil.Factory) *cobra.Command { | ||
cmd := aCmd.NewCmdAuth(f) | ||
return cmd | ||
} | ||
|
||
func GHConfig(f *cmdutil.Factory) *cobra.Command { | ||
cmd := cCmd.NewCmdConfig(f) | ||
return cmd | ||
} | ||
|
||
func Repo(f *cmdutil.Factory) *cobra.Command { | ||
repoResolvingCmdFactory := *f | ||
repoResolvingCmdFactory.BaseRepo = resolvedBaseRepo(f) | ||
|
||
cmd := rCmd.NewCmdRepo(&repoResolvingCmdFactory) | ||
|
||
return cmd | ||
} | ||
|
||
func resolvedBaseRepo(f *cmdutil.Factory) func() (ghrepo.Interface, error) { | ||
return func() (ghrepo.Interface, error) { | ||
httpClient, err := f.HttpClient() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
apiClient := api.NewClientFromHTTP(httpClient) | ||
|
||
remotes, err := f.Remotes() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
repoContext, err := context.ResolveRemotesToRepos(remotes, apiClient, "") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
baseRepo, err := repoContext.BaseRepo(f.IOStreams) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return baseRepo, nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
package app | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
"runtime" | ||
|
||
"github.com/abdfnx/gosh" | ||
"github.com/spf13/cobra" | ||
"github.com/abdfnx/gh/utils" | ||
"github.com/briandowns/spinner" | ||
"github.com/MakeNowJust/heredoc" | ||
"github.com/abdfnx/tran/constants" | ||
git_config "github.com/david-tomson/tran-git" | ||
) | ||
|
||
var username = git_config.GitConfig() | ||
|
||
var ( | ||
NewCmdStart = &cobra.Command{ | ||
Use: "start", | ||
Aliases: []string{"."}, | ||
Example: "tran sync start", | ||
Short: "Start sync your tran config.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if username != ":username" { | ||
exCmd := constants.StartEX() | ||
|
||
gosh.RunMulti(constants.Start_ml(), constants.Start_w()) | ||
gosh.Run(exCmd) | ||
} else { | ||
utils.AuthMessage() | ||
} | ||
}, | ||
} | ||
|
||
NewCmdClone = &cobra.Command{ | ||
Use: "clone", | ||
Aliases: []string{"cn"}, | ||
Short: CloneHelp(), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if username != ":username" { | ||
cloneCmd := constants.Clone() | ||
|
||
gosh.Run(cloneCmd) | ||
gosh.RunMulti(constants.Clone_check_ml(), constants.Clone_check_w()) | ||
} else { | ||
utils.AuthMessage() | ||
} | ||
}, | ||
} | ||
|
||
NewCmdPush = &cobra.Command{ | ||
Use: "push", | ||
Aliases: []string{"ph"}, | ||
Short: "Push the new changes in tran config file.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if username != ":username" { | ||
gosh.RunMulti(constants.Push_ml(), constants.Push_w()) | ||
} else { | ||
utils.AuthMessage() | ||
} | ||
}, | ||
} | ||
|
||
NewCmdPull = &cobra.Command{ | ||
Use: "pull", | ||
Aliases: []string{"pl"}, | ||
Short: PullHelp(), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if username != ":username" { | ||
gosh.RunMulti(constants.Pull_ml(), constants.Pull_w()) | ||
} else { | ||
utils.AuthMessage() | ||
} | ||
}, | ||
} | ||
|
||
FetchClone = &cobra.Command{ | ||
Use: "fetchx", | ||
Short: "Special command for windows", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if username != ":username" { | ||
if runtime.GOOS == "windows" { | ||
gosh.PowershellCommand(constants.Clone()) | ||
} else { | ||
fmt.Println("This command isn't avaliable for this platform") | ||
} | ||
} else { | ||
utils.AuthMessage() | ||
} | ||
}, | ||
} | ||
) | ||
|
||
func Sync() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "sync <command>", | ||
Short: "Sync your tran config file.", | ||
Long: SyncHelp(), | ||
Example: heredoc.Doc(` | ||
tran sync start | ||
tran sync clone | ||
`), | ||
} | ||
|
||
cmd.AddCommand(NewCmdStart) | ||
cmd.AddCommand(NewCmdClone) | ||
cmd.AddCommand(NewCmdPush) | ||
cmd.AddCommand(NewCmdPull) | ||
cmd.AddCommand(FetchClone) | ||
|
||
return cmd | ||
} | ||
|
||
const tranConfigPath string = "/.tran" | ||
|
||
func PullHelp() string { | ||
return git_config.GitConfigWithMsg("Pull the new changes from ", tranConfigPath) | ||
} | ||
|
||
func SyncHelp() string { | ||
return git_config.GitConfigWithMsg("Sync your config file, by create a private repo at ", tranConfigPath) | ||
} | ||
|
||
func CloneHelp() string { | ||
return git_config.GitConfigWithMsg("Clone your .tran from your private repo at https://github.com/", tranConfigPath) | ||
} | ||
|
||
func PushSync() { | ||
const Syncing string = " 📮 Syncing..." | ||
|
||
if runtime.GOOS == "windows" { | ||
err, out, errout := gosh.PowershellOutput( | ||
` | ||
$directoyPath = "~/.config/tran/.git" | ||
if (Test-Path -path $directoyPath) { | ||
Write-Host "Reading from .tran folder..." | ||
} | ||
`) | ||
|
||
fmt.Print(out) | ||
|
||
if err != nil { | ||
log.Printf("error: %v\n", err) | ||
fmt.Print(errout) | ||
} else if out != "" { | ||
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) | ||
s.Suffix = Syncing | ||
s.Start() | ||
|
||
gosh.PowershellCommand(constants.Push_w()) | ||
|
||
s.Stop() | ||
} | ||
} else { | ||
err, out, errout := gosh.ShellOutput( | ||
` | ||
if [ -d ~/.config/tran/.git ]; then | ||
echo "📖 Reading from .tran folder..." | ||
fi | ||
`) | ||
|
||
fmt.Print(out) | ||
|
||
if err != nil { | ||
log.Printf("error: %v\n", err) | ||
fmt.Print(errout) | ||
} else if out != "" { | ||
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) | ||
s.Suffix = Syncing | ||
s.Start() | ||
|
||
gosh.ShellCommand(constants.Push_ml()) | ||
|
||
s.Stop() | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.