Refactor autolink subcommands into their own packages
This commit is contained in:
parent
ea04d2da30
commit
e98ff2ea38
6 changed files with 19 additions and 21 deletions
|
|
@ -2,6 +2,7 @@ package autolink
|
|||
|
||||
import (
|
||||
"github.com/MakeNowJust/heredoc"
|
||||
cmdList "github.com/cli/cli/v2/pkg/cmd/repo/autolink/list"
|
||||
"github.com/cli/cli/v2/pkg/cmdutil"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
|
@ -22,7 +23,7 @@ func NewCmdAutolink(f *cmdutil.Factory) *cobra.Command {
|
|||
}
|
||||
cmdutil.EnableRepoOverride(cmd, f)
|
||||
|
||||
cmd.AddCommand(newCmdList(f, nil))
|
||||
cmd.AddCommand(cmdList.NewCmdList(f, nil))
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package autolink
|
||||
package list
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package autolink
|
||||
package list
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package autolink
|
||||
package list
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
@ -21,6 +21,17 @@ var autolinkFields = []string{
|
|||
"urlTemplate",
|
||||
}
|
||||
|
||||
type autolink struct {
|
||||
ID int `json:"id"`
|
||||
IsAlphanumeric bool `json:"is_alphanumeric"`
|
||||
KeyPrefix string `json:"key_prefix"`
|
||||
URLTemplate string `json:"url_template"`
|
||||
}
|
||||
|
||||
func (s *autolink) ExportData(fields []string) map[string]interface{} {
|
||||
return cmdutil.StructExportData(s, fields)
|
||||
}
|
||||
|
||||
type listOptions struct {
|
||||
BaseRepo func() (ghrepo.Interface, error)
|
||||
Browser browser.Browser
|
||||
|
|
@ -35,7 +46,7 @@ type AutolinkClient interface {
|
|||
Get(repo ghrepo.Interface) ([]autolink, error)
|
||||
}
|
||||
|
||||
func newCmdList(f *cmdutil.Factory, runF func(*listOptions) error) *cobra.Command {
|
||||
func NewCmdList(f *cmdutil.Factory, runF func(*listOptions) error) *cobra.Command {
|
||||
opts := &listOptions{
|
||||
Browser: f.Browser,
|
||||
IO: f.IOStreams,
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package autolink
|
||||
package list
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
|
@ -69,7 +69,7 @@ func TestNewCmdList(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
var gotOpts *listOptions
|
||||
cmd := newCmdList(f, func(opts *listOptions) error {
|
||||
cmd := NewCmdList(f, func(opts *listOptions) error {
|
||||
gotOpts = opts
|
||||
return nil
|
||||
})
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
package autolink
|
||||
|
||||
import "github.com/cli/cli/v2/pkg/cmdutil"
|
||||
|
||||
type autolink struct {
|
||||
ID int `json:"id"`
|
||||
IsAlphanumeric bool `json:"is_alphanumeric"`
|
||||
KeyPrefix string `json:"key_prefix"`
|
||||
URLTemplate string `json:"url_template"`
|
||||
}
|
||||
|
||||
func (s *autolink) ExportData(fields []string) map[string]interface{} {
|
||||
return cmdutil.StructExportData(s, fields)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue