command

package
v1.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2020 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	ProjectListFormatLabelShort    = "short"
	ProjectListFormatLabelSpec     = "spec"
	ProjectListFormatLabelFullPath = "full"
	ProjectListFormatLabelURL      = "url"
	ProjectListFormatLabelRelPath  = "relative"
)

ProjectListFormat choices.

Variables

This section is empty.

Functions

func Bulk

func Bulk(ev gogh.Env, gitClient GitClient, update, withSSH, shallow bool) error

Bulk get repositories specified in stdin.

func ConfigGet added in v1.0.0

func ConfigGet(cfg *env.Config, optionName string) error
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

func ConfigGetAll(cfg *env.Config) error
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

func ConfigSet(ev gogh.Env, cfg *env.Config, optionName, optionValue string) error
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

func ConfigUnset(ev gogh.Env, cfg *env.Config, optionName string) error
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 Delete added in v1.3.2

func Delete(ev gogh.Env, primary bool, query string) error

Delete local projects

func Find

func Find(ev gogh.Env, primary bool, spec *gogh.RepoSpec) error

Find a local project

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 InitLog added in v1.4.0

func InitLog()

func Initialize added in v1.6.0

func Initialize(ev gogh.Env, _, shell string) error

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

func List(ev gogh.Env, formatter gogh.ProjectListFormatter, primary bool, query string) error

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,
	fork,
	archived bool,
	visibility,
	sort,
	direction string,
	formatter gogh.ProjectListFormatter,
	query string,
) error

Repos will show a list of repositories for a user.

func Roots added in v1.5.0

func Roots(ev gogh.Env, all bool) error

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

func Setup

func Setup(_ context.Context, ev gogh.Env, cfg *env.Config, force bool) error

func Statuses added in v1.7.0

func Statuses(ev gogh.Env, gitClient GitClient, formatter gogh.ProjectListFormatter, primary bool, query string, detail bool) (retErr error)

Statuses shows all statuses of the gogh projects.

func Where added in v0.3.2

func Where(ev gogh.Env, primary bool, query string) error

Where is a local project

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)
	GetStatusSummary(string, io.Writer) (git.StatusSummary, error)
	Init(string, bool, string, string, string) error
	RemoveRemote(string, string) error
	RenameRemote(string, string, string) error
	SetUpstreamTo(string, string) error
	Status(string, io.Writer, io.Writer) error
	Update(string) error
}

GitClient is an interface generated for "github.com/kyoh86/gogh/internal/git.Client".

type HubClient added in v1.4.0

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 (*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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL