Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
git-bug
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
MichaelMure
git-bug
Commits
d37ffa6b
Unverified
Commit
d37ffa6b
authored
Oct 17, 2018
by
Michael Muré
Browse files
Options
Downloads
Patches
Plain Diff
commands: unify the processing from editor/file/stdin for "add" and "comment add"
fix #68
parent
f67c57c0
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
commands/add.go
+8
-8
8 additions, 8 deletions
commands/add.go
commands/comment_add.go
+2
-2
2 additions, 2 deletions
commands/comment_add.go
input/input.go
+32
-2
32 additions, 2 deletions
input/input.go
with
42 additions
and
12 deletions
commands/add.go
+
8
−
8
View file @
d37ffa6b
...
...
@@ -17,20 +17,20 @@ var (
func
runAddBug
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
var
err
error
if
addMessageFile
!=
""
&&
addMessage
==
""
{
addMessage
,
err
=
input
.
FromFile
(
addMessageFile
)
backend
,
err
:=
cache
.
NewRepoCache
(
repo
)
if
err
!=
nil
{
return
err
}
}
defer
backend
.
Close
()
backend
,
err
:=
cache
.
NewRepoCache
(
repo
)
if
addMessageFile
!=
""
&&
addMessage
==
""
{
addTitle
,
addMessage
,
err
=
input
.
BugCreateFileInput
(
addMessageFile
)
if
err
!=
nil
{
return
err
}
defer
backend
.
Close
()
}
if
addMessage
==
""
||
addTitle
==
""
{
if
addMessageFile
==
""
&&
(
addMessage
==
""
||
addTitle
==
""
)
{
addTitle
,
addMessage
,
err
=
input
.
BugCreateEditorInput
(
backend
,
addTitle
,
addMessage
)
if
err
==
input
.
ErrEmptyTitle
{
...
...
This diff is collapsed.
Click to expand it.
commands/comment_add.go
+
2
−
2
View file @
d37ffa6b
...
...
@@ -27,13 +27,13 @@ func runCommentAdd(cmd *cobra.Command, args []string) error {
}
if
commentAddMessageFile
!=
""
&&
commentAddMessage
==
""
{
commentAddMessage
,
err
=
input
.
FromFile
(
commentAddMessageFile
)
commentAddMessage
,
err
=
input
.
BugCommentFileInput
(
commentAddMessageFile
)
if
err
!=
nil
{
return
err
}
}
if
commentAddMessage
==
""
{
if
commentAddMessageFile
==
""
&&
commentAddMessage
==
""
{
commentAddMessage
,
err
=
input
.
BugCommentEditorInput
(
backend
,
""
)
if
err
==
input
.
ErrEmptyMessage
{
fmt
.
Println
(
"Empty message, aborting."
)
...
...
This diff is collapsed.
Click to expand it.
input/input.go
+
32
−
2
View file @
d37ffa6b
...
...
@@ -48,6 +48,21 @@ func BugCreateEditorInput(repo repository.RepoCommon, preTitle string, preMessag
return
""
,
""
,
err
}
return
processCreate
(
raw
)
}
// BugCreateFileInput read from either from a file or from the standard input
// and extract a title and a message
func
BugCreateFileInput
(
fileName
string
)
(
string
,
string
,
error
)
{
raw
,
err
:=
fromFile
(
fileName
)
if
err
!=
nil
{
return
""
,
""
,
err
}
return
processCreate
(
raw
)
}
func
processCreate
(
raw
string
)
(
string
,
string
,
error
)
{
lines
:=
strings
.
Split
(
raw
,
"
\n
"
)
var
title
string
...
...
@@ -94,6 +109,21 @@ func BugCommentEditorInput(repo repository.RepoCommon, preMessage string) (strin
return
""
,
err
}
return
processComment
(
raw
)
}
// BugCommentFileInput read from either from a file or from the standard input
// and extract a message
func
BugCommentFileInput
(
fileName
string
)
(
string
,
error
)
{
raw
,
err
:=
fromFile
(
fileName
)
if
err
!=
nil
{
return
""
,
err
}
return
processComment
(
raw
)
}
func
processComment
(
raw
string
)
(
string
,
error
)
{
lines
:=
strings
.
Split
(
raw
,
"
\n
"
)
var
buffer
bytes
.
Buffer
...
...
@@ -266,11 +296,11 @@ func launchEditor(repo repository.RepoCommon, fileName string) (string, error) {
return
string
(
output
),
err
}
//
F
romFile loads and returns the contents of a given file. If - is passed
//
f
romFile loads and returns the contents of a given file. If - is passed
// through, much like git, it will read from stdin. This can be piped data,
// unless there is a tty in which case the user will be prompted to enter a
// message.
func
F
romFile
(
fileName
string
)
(
string
,
error
)
{
func
f
romFile
(
fileName
string
)
(
string
,
error
)
{
if
fileName
==
"-"
{
stat
,
err
:=
os
.
Stdin
.
Stat
()
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment