Documentation
¶
Index ¶
- Constants
- func Bulk(ev gogh.Env, gitClient GitClient, update, withSSH, shallow bool) error
- func ConfigGet(cfg *env.Config, optionName string) error
- func ConfigGetAll(cfg *env.Config) error
- func ConfigSet(ev gogh.Env, cfg *env.Config, optionName, optionValue string) error
- func ConfigUnset(ev gogh.Env, cfg *env.Config, optionName string) error
- func Delete(ev gogh.Env, primary bool, query string) error
- func Find(ev gogh.Env, primary bool, spec *gogh.RepoSpec) error
- func Fork(ctx context.Context, ev gogh.Env, gitClient GitClient, hubClient HubClient, ...) error
- func Get(ev gogh.Env, gitClient GitClient, update, withSSH, shallow bool, ...) error
- func GetAll(ev gogh.Env, gitClient GitClient, update, withSSH, shallow bool, ...) error
- func InitLog()
- func Initialize(ev gogh.Env, _, shell string) error
- func List(ev gogh.Env, formatter gogh.ProjectListFormatter, primary bool, query string) error
- func New(ctx context.Context, ev gogh.Env, gitClient GitClient, hubClient HubClient, ...) error
- func Pipe(ev gogh.Env, gitClient GitClient, update, withSSH, shallow bool, ...) (retErr error)
- func ProjectListFormats() []string
- func Repos(ctx context.Context, ev gogh.Env, hubClient HubClient, user string, ...) error
- func Roots(ev gogh.Env, all bool) error
- func Setup(_ context.Context, ev gogh.Env, cfg *env.Config, force bool) error
- func Where(ev gogh.Env, primary bool, query string) error
- type GitClient
- type HubClient
- type ProjectListFormat
- type RepoShared
Examples ¶
Constants ¶
const ( ProjectListFormatLabelShort = "short" ProjectListFormatLabelFullPath = "full" ProjectListFormatLabelURL = "url" ProjectListFormatLabelRelPath = "relative" )
ProjectListFormat choices.
Variables ¶
This section is empty.
Functions ¶
func ConfigGet ¶ added in v1.0.0
Example ¶
package main import ( "log" "strings" "github.com/kyoh86/gogh/command" "github.com/kyoh86/gogh/env" ) func main() { yml := strings.NewReader(`{"roots": ["/foo", "/bar"]}`) config, err := env.GetConfig(yml) if err != nil { log.Fatalln(err) } if err := command.ConfigGet(&config, "roots"); err != nil { log.Fatalln(err) } }
Output: /foo:/bar
func ConfigGetAll ¶ added in v1.0.0
Example ¶
package main import ( "log" "strings" "github.com/kyoh86/gogh/command" "github.com/kyoh86/gogh/env" ) func main() { yml := strings.NewReader(` roots: - /root1 - /root2 hooks: - /hook1 - /hook2 githubHost: hostx1 githubUser: userx1`) config, err := env.GetConfig(yml) if err != nil { log.Fatalln(err) } if err := command.ConfigGetAll(&config); err != nil { log.Fatalln(err) } }
Output: roots: /root1:/root2 hooks: /hook1:/hook2 github.host: hostx1 github.user: userx1 github.token: *****
func ConfigSet ¶ added in v1.5.0
Example ¶
package main import ( "log" "os" "strings" "github.com/kyoh86/gogh/command" "github.com/kyoh86/gogh/env" ) func main() { source := strings.NewReader(` roots: - /root1 hooks: - /hook1 githubUser: userx1 githubHost: hostx1`) config, access, err := env.GetAppenv(source, env.EnvarPrefix) if err != nil { log.Fatalln(err) } if err := command.ConfigSet(&access, &config, "github.host", "hostx2"); err != nil { log.Fatalln(err) } if err := config.Save(os.Stdout); err != nil { log.Fatalln(err) } if err := command.ConfigGetAll(&config); err != nil { log.Fatalln(err) } }
Output: roots: - /root1 hooks: - /hook1 githubHost: hostx2 githubUser: userx1 roots: /root1 hooks: /hook1 github.host: hostx2 github.user: userx1 github.token: *****
func ConfigUnset ¶ added in v1.0.0
Example ¶
package main import ( "log" "os" "strings" "github.com/kyoh86/gogh/command" "github.com/kyoh86/gogh/env" ) func main() { source := strings.NewReader(` roots: - /root1 hooks: - /hook1 githubUser: userx1 githubHost: hostx1`) config, access, err := env.GetAppenv(source, env.EnvarPrefix) if err != nil { log.Fatalln(err) } if err := command.ConfigUnset(&access, &config, "github.host"); err != nil { log.Fatalln(err) } if err := config.Save(os.Stdout); err != nil { log.Fatalln(err) } if err := command.ConfigGetAll(&config); err != nil { log.Fatalln(err) } }
Output: roots: - /root1 hooks: - /hook1 githubUser: userx1 roots: /root1 hooks: /hook1 github.host: github.user: userx1 github.token: *****
func Fork ¶
func Fork(ctx context.Context, ev gogh.Env, gitClient GitClient, hubClient HubClient, update, withSSH, shallow bool, organization string, spec *gogh.RepoSpec) error
Fork clone/sync with a remote repository make a fork of a remote repository on GitHub and add GitHub as origin
func Get ¶
func Get(ev gogh.Env, gitClient GitClient, update, withSSH, shallow bool, spec *gogh.RepoSpec) error
Get clones or updates a remote repository. If update is true, updates the locally cloned repository. Otherwise does nothing. If shallow is true, does shallow cloning. (no effect if already cloned or the VCS is Mercurial and git-svn)
func GetAll ¶
func GetAll(ev gogh.Env, gitClient GitClient, update, withSSH, shallow bool, specs gogh.RepoSpecs) error
GetAll clonse or updates remote repositories.
func Initialize ¶ added in v1.6.0
Initialize shells in shell scipt Usage: eval "$(gogh init)"
Example (Bash) ¶
package main import ( "github.com/kyoh86/gogh/command" ) func main() { if err := command.Initialize(nil, "gogh-cd", "bash"); err != nil { panic(err) } }
Output: #!/bin/bash function gogh() { case $1 in "cd" ) shift cd "$(command gogh find "$@" | tee /dev/tty | tail -n1)" || return ;; "get" ) local CD=0 for arg in "$@"; do if [ "${arg}" = '--cd' ]; then CD=1 fi done if [ $CD -eq 1 ]; then loc="$(command gogh "$@" | tee /dev/tty | tail -n1)" cd "$loc" || return else command gogh "$@" fi ;; * ) command gogh "$@" ;; esac } eval "$(command gogh --completion-script-bash)"
Example (Zsh) ¶
package main import ( "github.com/kyoh86/gogh/command" ) func main() { if err := command.Initialize(nil, "gogh-cd", "zsh"); err != nil { panic(err) } }
Output: function gogh() { exec 5>&1 case $1 in "cd" ) shift cd "$(command gogh find "$@" | tee /dev/tty | tail -n1)" || return ;; "get" ) local CD=0 for arg in "$@"; do if [ "${arg}" = '--cd' ]; then CD=1 fi done if [ $CD -eq 1 ]; then loc="$(command gogh "$@" | tee /dev/tty | tail -n1)" cd "$loc" || return else command gogh "$@" fi ;; * ) command gogh "$@" ;; esac } eval "$(command gogh --completion-script-zsh)"
func List ¶
List local projects
Example (Custom) ¶
package main import ( "io/ioutil" "os" "path/filepath" "strings" "github.com/kyoh86/gogh/command" "github.com/kyoh86/gogh/env" "github.com/kyoh86/gogh/gogh" ) func main() { tmp, _ := ioutil.TempDir(os.TempDir(), "gogh-test") defer os.RemoveAll(tmp) _ = os.MkdirAll(filepath.Join(tmp, "example.com", "kyoh86", "gogh", ".git"), 0755) _ = os.MkdirAll(filepath.Join(tmp, "example.com", "owner", "name", ".git"), 0755) _ = os.MkdirAll(filepath.Join(tmp, "example.com", "owner", "empty"), 0755) yml := strings.NewReader("githubHost: example.com\nroots:\n - " + tmp) config, err := env.GetAccess(yml, env.EnvarPrefix) if err != nil { panic(err) } fmter, err := gogh.CustomFormatter("{{short .}};;{{relative .}}") if err != nil { panic(err) } if err := command.List(&config, fmter, true, "", ); err != nil { panic(err) } }
Output: gogh;;example.com/kyoh86/gogh name;;example.com/owner/name
Example (Url) ¶
package main import ( "io/ioutil" "os" "path/filepath" "strings" "github.com/kyoh86/gogh/command" "github.com/kyoh86/gogh/env" "github.com/kyoh86/gogh/gogh" ) func main() { tmp, _ := ioutil.TempDir(os.TempDir(), "gogh-test") defer os.RemoveAll(tmp) _ = os.MkdirAll(filepath.Join(tmp, "example.com", "kyoh86", "gogh", ".git"), 0755) _ = os.MkdirAll(filepath.Join(tmp, "example.com", "owner", "name", ".git"), 0755) _ = os.MkdirAll(filepath.Join(tmp, "example.com", "owner", "empty"), 0755) yml := strings.NewReader("githubHost: example.com\nroots:\n - " + tmp) config, err := env.GetAccess(yml, env.EnvarPrefix) if err != nil { panic(err) } if err := command.List(&config, gogh.URLFormatter(), true, "", ); err != nil { panic(err) } }
Output: https://example.com/kyoh86/gogh https://example.com/owner/name
func New ¶
func New( ctx context.Context, ev gogh.Env, gitClient GitClient, hubClient HubClient, private bool, description string, homepage *url.URL, bare bool, template string, separateGitDir string, shared RepoShared, spec *gogh.RepoSpec, ) error
New creates a local project and a remote repository.
func Pipe ¶
func Pipe(ev gogh.Env, gitClient GitClient, update, withSSH, shallow bool, command string, commandArgs []string) (retErr error)
Pipe handles like `gogh pipe github-list-starred kyoh86` calling `github-list-starred kyoh86` and bulk its output
func ProjectListFormats ¶ added in v1.3.0
func ProjectListFormats() []string
ProjectListFormats shows all of ProjectListFormat constants.
func Repos ¶ added in v1.0.0
func Repos(ctx context.Context, ev gogh.Env, hubClient HubClient, user string, own, collaborate, member, archived bool, visibility, sort, direction string) error
Repos will show a list of repositories for a user.
func Roots ¶ added in v1.5.0
Roots prints a gogh.root
Example ¶
package main import ( "fmt" "strings" "github.com/kyoh86/gogh/command" "github.com/kyoh86/gogh/env" ) func main() { yml := strings.NewReader("roots:\n - /foo\n - /bar") config, err := env.GetAccess(yml, env.EnvarPrefix) if err != nil { panic(err) } if err := command.Roots(&config, false); err != nil { panic(err) } fmt.Println() if err := command.Roots(&config, true); err != nil { panic(err) } }
Output: /foo /foo /bar
Types ¶
type GitClient ¶ added in v1.4.0
type GitClient interface { AddRemote(string, string, *url.URL) error Clone(string, *url.URL, bool) error Fetch(string) error GetCurrentBranch(string) (string, error) GetRemote(string, string) (*url.URL, error) GetRemotes(string) (map[string]*url.URL, error) Init(string, bool, string, string, string) error RemoveRemote(string, string) error RenameRemote(string, string, string) error SetUpstreamTo(string, string) error Update(string) error }
GitClient is an interface generated for "github.com/kyoh86/gogh/internal/git.Client".
type HubClient ¶ added in v1.4.0
type HubClient interface { Create(context.Context, gogh.Env, *gogh.Repo, string, *url.URL, bool) (*github.Repository, error) Fork(context.Context, gogh.Env, *gogh.Repo, string) (*gogh.Repo, error) Repos(context.Context, gogh.Env, string, bool, bool, bool, bool, string, string, string) ([]string, error) }
HubClient is an interface generated for "github.com/kyoh86/gogh/internal/hub.Client".
type ProjectListFormat ¶ added in v1.3.0
type ProjectListFormat struct {
// contains filtered or unexported fields
}
ProjectListFormat specifies how gogh prints a project.
func (*ProjectListFormat) Formatter ¶ added in v1.3.0
func (f *ProjectListFormat) Formatter() gogh.ProjectListFormatter
func (*ProjectListFormat) Set ¶ added in v1.3.0
func (f *ProjectListFormat) Set(value string) error
func (ProjectListFormat) String ¶ added in v1.3.0
func (f ProjectListFormat) String() string
type RepoShared ¶ added in v1.4.0
type RepoShared string
RepoShared notices file shared flag like group, all, everybody, 0766.
func (*RepoShared) Set ¶ added in v1.4.0
func (s *RepoShared) Set(text string) error
Set text as RepoShared
func (RepoShared) String ¶ added in v1.4.0
func (s RepoShared) String() string