mirror of https://gitlab.com/gitlab-org/cli.git
feat(mr): support minimal unified diff output for mr diff
- Modify mr diff output to provide a minimum unified diff support - Document glab_pager configuration in glab config command
This commit is contained in:
parent
34b7168442
commit
b58c1255ed
|
@ -4,16 +4,17 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/MakeNowJust/heredoc"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/profclems/glab/commands/cmdutils"
|
||||
"github.com/profclems/glab/internal/config"
|
||||
"github.com/profclems/glab/pkg/glinstance"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var isGlobal bool
|
||||
|
||||
func NewCmdConfig(f *cmdutils.Factory) *cobra.Command {
|
||||
var configCmd = &cobra.Command{
|
||||
configCmd := &cobra.Command{
|
||||
Use: "config [flags]",
|
||||
Short: `Set and get glab settings`,
|
||||
Long: heredoc.Doc(`Get and set key/value strings.
|
||||
|
@ -26,6 +27,7 @@ Current respected settings:
|
|||
- editor: if unset, defaults to environment variables.
|
||||
- visual: alternative for editor. if unset, defaults to environment variables.
|
||||
- glamour_style: Your desired markdown renderer style. Options are dark, light, notty. Custom styles are allowed set a custom style https://github.com/charmbracelet/glamour#styles
|
||||
- glab_pager: Your desired pager command to use (e.g. less -R)
|
||||
`),
|
||||
Aliases: []string{"conf"},
|
||||
}
|
||||
|
@ -133,7 +135,7 @@ Specifying the --hostname flag also saves in the global config file
|
|||
}
|
||||
|
||||
func NewCmdConfigInit(f *cmdutils.Factory) *cobra.Command {
|
||||
var configInitCmd = &cobra.Command{
|
||||
configInitCmd := &cobra.Command{
|
||||
Use: "init",
|
||||
Short: "Shows a prompt to set basic glab configuration",
|
||||
Long: `Update the configuration by setting a key to a value.
|
||||
|
|
|
@ -13,9 +13,10 @@ import (
|
|||
"github.com/profclems/glab/pkg/iostreams"
|
||||
|
||||
"github.com/MakeNowJust/heredoc"
|
||||
"github.com/xanzy/go-gitlab"
|
||||
|
||||
"github.com/profclems/glab/commands/cmdutils"
|
||||
"github.com/profclems/glab/commands/mr/mrutils"
|
||||
"github.com/xanzy/go-gitlab"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
@ -45,7 +46,6 @@ func NewCmdDiff(f *cmdutils.Factory, runF func(*DiffOptions) error) *cobra.Comma
|
|||
`),
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
if repoOverride, _ := cmd.Flags().GetString("repo"); repoOverride != "" && len(args) == 0 {
|
||||
return &cmdutils.FlagError{Err: errors.New("argument required when using the --repo flag")}
|
||||
}
|
||||
|
@ -97,14 +97,9 @@ func diffRun(opts *DiffOptions) error {
|
|||
return fmt.Errorf("could not find merge request diff: %w", err)
|
||||
}
|
||||
for _, diffLine := range diffVersion.Diffs {
|
||||
if diffLine.RenamedFile {
|
||||
diffOut.WriteString("-" + diffLine.OldPath + "\n")
|
||||
}
|
||||
if diffLine.NewFile || diffLine.RenamedFile {
|
||||
diffOut.WriteString("+" + diffLine.NewPath + "\n")
|
||||
} else {
|
||||
diffOut.WriteString(diffLine.OldPath + "\n")
|
||||
}
|
||||
// output the unified diff header
|
||||
diffOut.WriteString("--- " + diffLine.OldPath + "\n")
|
||||
diffOut.WriteString("+++ " + diffLine.NewPath + "\n")
|
||||
|
||||
diffOut.WriteString(diffLine.Diff)
|
||||
}
|
||||
|
|
|
@ -20,10 +20,10 @@ type IOStreams struct {
|
|||
StdOut io.Writer
|
||||
StdErr io.Writer
|
||||
|
||||
IsaTTY bool //stdout is a tty
|
||||
IsErrTTY bool //stderr is a tty
|
||||
IsInTTY bool //stdin is a tty
|
||||
promptDisabled bool //disable prompting for input
|
||||
IsaTTY bool // stdout is a tty
|
||||
IsErrTTY bool // stderr is a tty
|
||||
IsInTTY bool // stdin is a tty
|
||||
promptDisabled bool // disable prompting for input
|
||||
|
||||
is256ColorEnabled bool
|
||||
|
||||
|
@ -171,7 +171,7 @@ func (s *IOStreams) TerminalWidth() int {
|
|||
return TerminalWidth(s.StdOut)
|
||||
}
|
||||
|
||||
//IsOutputTTY returns true if both stdout and stderr is TTY
|
||||
// IsOutputTTY returns true if both stdout and stderr is TTY
|
||||
func (s *IOStreams) IsOutputTTY() bool {
|
||||
return s.IsErrTTY && s.IsaTTY
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue