-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
63 changed files
with
2,520 additions
and
793 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
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,42 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/kyoh86/gogh/config" | ||
) | ||
|
||
func ConfigGetAll(cfg *config.Config) error { | ||
for _, name := range config.OptionNames() { | ||
opt, _ := config.Option(name) // ignore error: config.OptionNames covers all accessor | ||
value := opt.Get(cfg) | ||
fmt.Printf("%s = %s\n", name, value) | ||
} | ||
return nil | ||
} | ||
|
||
func ConfigGet(cfg *config.Config, optionName string) error { | ||
opt, err := config.Option(optionName) | ||
if err != nil { | ||
return err | ||
} | ||
value := opt.Get(cfg) | ||
fmt.Println(value) | ||
return nil | ||
} | ||
|
||
func ConfigPut(cfg *config.Config, optionName, optionValue string) error { | ||
opt, err := config.Option(optionName) | ||
if err != nil { | ||
return err | ||
} | ||
return opt.Put(cfg, optionValue) | ||
} | ||
|
||
func ConfigUnset(cfg *config.Config, optionName string) error { | ||
opt, err := config.Option(optionName) | ||
if err != nil { | ||
return err | ||
} | ||
return opt.Unset(cfg) | ||
} |
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,40 @@ | ||
package command_test | ||
|
||
import ( | ||
"github.com/kyoh86/gogh/command" | ||
"github.com/kyoh86/gogh/config" | ||
) | ||
|
||
func ExampleConfigGetAll() { | ||
if err := command.ConfigGetAll(&config.Config{ | ||
GitHub: config.GitHubConfig{ | ||
Token: "tokenx1", | ||
Host: "hostx1", | ||
User: "kyoh86", | ||
}, | ||
Log: config.LogConfig{ | ||
Level: "trace", | ||
Date: config.TrueOption, | ||
Time: config.FalseOption, | ||
MicroSeconds: config.TrueOption, | ||
LongFile: config.TrueOption, | ||
ShortFile: config.TrueOption, | ||
UTC: config.TrueOption, | ||
}, | ||
VRoot: []string{"/foo", "/bar"}, | ||
}); err != nil { | ||
panic(err) | ||
} | ||
// Unordered output: | ||
// root = /foo:/bar | ||
// github.host = hostx1 | ||
// github.user = kyoh86 | ||
// github.token = tokenx1 | ||
// log.level = trace | ||
// log.date = yes | ||
// log.time = no | ||
// log.microseconds = yes | ||
// log.longfile = yes | ||
// log.shortfile = yes | ||
// log.utc = yes | ||
} |
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,23 @@ | ||
package command_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/kyoh86/gogh/command" | ||
"github.com/kyoh86/gogh/config" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func ExampleConfigGet() { | ||
if err := command.ConfigGet(&config.Config{ | ||
VRoot: []string{"/foo", "/bar"}, | ||
}, "root"); err != nil { | ||
panic(err) | ||
} | ||
// Output: | ||
// /foo:/bar | ||
} | ||
|
||
func TestConfigGet(t *testing.T) { | ||
assert.EqualError(t, command.ConfigGet(&config.Config{}, "invalid.name"), "invalid option name") | ||
} |
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,15 @@ | ||
package command_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/kyoh86/gogh/command" | ||
"github.com/kyoh86/gogh/config" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConfigPut(t *testing.T) { | ||
var cfg config.Config | ||
assert.NoError(t, command.ConfigPut(&cfg, "github.host", "hostx1")) | ||
assert.EqualError(t, command.ConfigPut(&cfg, "invalid.name", "hostx2"), "invalid option name") | ||
} |
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,20 @@ | ||
package command_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/kyoh86/gogh/command" | ||
"github.com/kyoh86/gogh/config" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConfigUnset(t *testing.T) { | ||
cfg := config.Config{ | ||
GitHub: config.GitHubConfig{ | ||
Host: "hostx1", | ||
}, | ||
} | ||
assert.NoError(t, command.ConfigUnset(&cfg, "github.host")) | ||
assert.Empty(t, cfg.GitHub.Host) | ||
assert.EqualError(t, command.ConfigUnset(&cfg, "invalid.name"), "invalid option name") | ||
} |
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,46 @@ | ||
package command | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/kyoh86/gogh/gogh" | ||
"github.com/kyoh86/gogh/internal/context" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestEmpty(t *testing.T) { | ||
defaultGitClient = &mockGitClient{} | ||
defaultHubClient = &mockHubClient{} | ||
tmp, err := ioutil.TempDir(os.TempDir(), "gogh-test") | ||
require.NoError(t, err) | ||
defer os.RemoveAll(tmp) | ||
ctx := &context.MockContext{ | ||
MRoot: []string{tmp}, | ||
MGitHubHost: "github.com", | ||
} | ||
|
||
assert.NoError(t, Pipe(ctx, false, false, false, "echo", []string{"kyoh86/gogh"})) | ||
ctx.MStdin = strings.NewReader(`kyoh86/gogh`) | ||
assert.NoError(t, Bulk(ctx, false, false, false)) | ||
mustRepo := func(name string) *gogh.Repo { | ||
t.Helper() | ||
repo, err := gogh.ParseRepo(name) | ||
require.NoError(t, err) | ||
return repo | ||
} | ||
assert.NoError(t, GetAll(ctx, false, false, false, gogh.Repos{ | ||
*mustRepo("kyoh86/gogh"), | ||
*mustRepo("kyoh86/vim-gogh"), | ||
})) | ||
assert.NoError(t, Get(ctx, false, false, false, mustRepo("kyoh86/gogh"))) | ||
assert.NoError(t, Fork(ctx, false, false, false, false, "", "", mustRepo("kyoh86/gogh"))) | ||
assert.NoError(t, List(ctx, gogh.ProjectListFormatShort, false, "")) | ||
proj1 := filepath.Join(tmp, "github.com", "kyoh86", "gogh", ".git") | ||
require.NoError(t, os.MkdirAll(proj1, 0755)) | ||
assert.NoError(t, Root(ctx, false)) | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.