Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-shell
Commits
412ed17c
Commit
412ed17c
authored
Sep 11, 2019
by
Ash McKenzie
Committed by
Igor Drozdov
Oct 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New console package for writing to the console
parent
629e3bf9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
274 additions
and
0 deletions
+274
-0
internal/console/console.go
internal/console/console.go
+73
-0
internal/console/console_test.go
internal/console/console_test.go
+201
-0
No files found.
internal/console/console.go
0 → 100644
View file @
412ed17c
package
console
import
(
"fmt"
"io"
"strings"
)
func
DisplayWarningMessage
(
message
string
,
out
io
.
Writer
)
{
DisplayWarningMessages
([]
string
{
message
},
out
)
}
func
DisplayInfoMessage
(
message
string
,
out
io
.
Writer
)
{
DisplayInfoMessages
([]
string
{
message
},
out
)
}
func
DisplayWarningMessages
(
messages
[]
string
,
out
io
.
Writer
)
{
DisplayMessages
(
messages
,
out
,
true
)
}
func
DisplayInfoMessages
(
messages
[]
string
,
out
io
.
Writer
)
{
DisplayMessages
(
messages
,
out
,
false
)
}
func
DisplayMessages
(
messages
[]
string
,
out
io
.
Writer
,
displayDivider
bool
)
{
if
noMessages
(
messages
)
{
return
}
displayBlankLineOrDivider
(
out
,
displayDivider
)
for
_
,
msg
:=
range
messages
{
fmt
.
Fprintf
(
out
,
formatLine
(
msg
))
}
displayBlankLineOrDivider
(
out
,
displayDivider
)
}
func
noMessages
(
messages
[]
string
)
bool
{
if
len
(
messages
)
==
0
{
return
true
}
for
_
,
msg
:=
range
messages
{
if
len
(
strings
.
TrimSpace
(
msg
))
>
0
{
return
false
}
}
return
true
}
func
formatLine
(
message
string
)
string
{
return
fmt
.
Sprintf
(
"remote: %v
\n
"
,
message
)
}
func
displayBlankLineOrDivider
(
out
io
.
Writer
,
displayDivider
bool
)
{
if
displayDivider
{
fmt
.
Fprintf
(
out
,
divider
())
}
else
{
fmt
.
Fprintf
(
out
,
blankLine
())
}
}
func
blankLine
()
string
{
return
formatLine
(
""
)
}
func
divider
()
string
{
ruler
:=
strings
.
Repeat
(
"="
,
72
)
return
fmt
.
Sprintf
(
"%v%v%v"
,
blankLine
(),
formatLine
(
ruler
),
blankLine
())
}
internal/console/console_test.go
0 → 100644
View file @
412ed17c
package
console
import
(
"bytes"
"testing"
"github.com/stretchr/testify/require"
)
func
TestDisplayWarningMessage
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
message
string
wantOut
string
}{
{
name
:
"empty"
,
message
:
""
,
wantOut
:
""
,
},
{
name
:
"basically empty"
,
message
:
" "
,
wantOut
:
""
,
},
{
name
:
"something"
,
message
:
"something"
,
wantOut
:
`remote:
remote: ========================================================================
remote:
remote: something
remote:
remote: ========================================================================
remote:
`
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
out
:=
&
bytes
.
Buffer
{}
DisplayWarningMessage
(
tt
.
message
,
out
)
require
.
Equal
(
t
,
tt
.
wantOut
,
out
.
String
())
})
}
}
func
TestDisplayWarningMessages
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
messages
[]
string
wantOut
string
}{
{
name
:
"empty"
,
messages
:
[]
string
{
""
},
wantOut
:
""
,
},
{
name
:
"basically empty"
,
messages
:
[]
string
{
" "
},
wantOut
:
""
,
},
{
name
:
"something"
,
messages
:
[]
string
{
"something"
,
"here"
},
wantOut
:
`remote:
remote: ========================================================================
remote:
remote: something
remote: here
remote:
remote: ========================================================================
remote:
`
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
out
:=
&
bytes
.
Buffer
{}
DisplayWarningMessages
(
tt
.
messages
,
out
)
require
.
Equal
(
t
,
tt
.
wantOut
,
out
.
String
())
})
}
}
func
TestDisplayInfoMessage
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
message
string
wantOut
string
}{
{
name
:
"empty"
,
message
:
""
,
wantOut
:
""
,
},
{
name
:
"basically empty"
,
message
:
" "
,
wantOut
:
""
,
},
{
name
:
"something"
,
message
:
"something"
,
wantOut
:
`remote:
remote: something
remote:
`
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
out
:=
&
bytes
.
Buffer
{}
DisplayInfoMessage
(
tt
.
message
,
out
)
require
.
Equal
(
t
,
tt
.
wantOut
,
out
.
String
())
})
}
}
func
TestDisplayInfoMessages
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
messages
[]
string
wantOut
string
}{
{
name
:
"empty"
,
messages
:
[]
string
{
""
},
wantOut
:
""
,
},
{
name
:
"basically empty"
,
messages
:
[]
string
{
" "
},
wantOut
:
""
,
},
{
name
:
"something"
,
messages
:
[]
string
{
"something"
,
"here"
},
wantOut
:
"remote:
\n
remote: something
\n
remote: here
\n
remote:
\n
"
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
out
:=
&
bytes
.
Buffer
{}
DisplayInfoMessages
(
tt
.
messages
,
out
)
require
.
Equal
(
t
,
tt
.
wantOut
,
out
.
String
())
})
}
}
func
Test_noMessages
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
messages
[]
string
want
bool
}{
{
name
:
"empty"
,
messages
:
[]
string
{
""
},
want
:
true
,
},
{
name
:
"basically empty"
,
messages
:
[]
string
{
" "
},
want
:
true
,
},
{
name
:
"something"
,
messages
:
[]
string
{
"something"
,
"here"
},
want
:
false
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
require
.
Equal
(
t
,
tt
.
want
,
noMessages
(
tt
.
messages
))
})
}
}
func
Test_formatLine
(
t
*
testing
.
T
)
{
require
.
Equal
(
t
,
"remote: something
\n
"
,
formatLine
(
"something"
))
}
func
Test_divider
(
t
*
testing
.
T
)
{
want
:=
`remote:
remote: ========================================================================
remote:
`
require
.
Equal
(
t
,
want
,
divider
())
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment