Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
ion
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Enzo Cioppettini
ion
Commits
a1c8c9dd
Commit
a1c8c9dd
authored
7 years ago
by
Michael Aaron Murphy
Browse files
Options
Downloads
Patches
Plain Diff
Optimize let variable listing
parent
ace07de2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/builtins/mod.rs
+33
-2
33 additions, 2 deletions
src/builtins/mod.rs
with
33 additions
and
2 deletions
src/builtins/mod.rs
+
33
−
2
View file @
a1c8c9dd
...
...
@@ -22,7 +22,7 @@ use self::variables::{alias, drop_alias, drop_array, drop_variable};
use
fnv
::
FnvHashMap
;
use
std
::
error
::
Error
;
use
std
::
io
::{
self
,
Write
};
use
std
::
io
::{
self
,
Write
,
BufWriter
};
use
parser
::
QuoteTerminator
;
use
shell
::{
self
,
FlowLogic
,
Shell
,
ShellHistory
};
...
...
@@ -178,9 +178,40 @@ impl Builtin {
// Definitions of simple builtins go here
fn
list_vars
(
_
:
&
[
&
str
],
shell
:
&
mut
Shell
)
->
i32
{
let
stdout
=
io
::
stdout
();
let
mut
buffer
=
BufWriter
::
new
(
stdout
.lock
());
// Small function for formatting and append an array entry to a string buffer.
fn
print_array
<
W
:
Write
>
(
buffer
:
&
mut
W
,
key
:
&
str
,
array
:
&
[
String
])
{
let
_
=
buffer
.write
([
key
,
" = [ "
]
.concat
()
.as_bytes
());
if
array
.len
()
>
1
{
let
mut
vars
=
array
.iter
();
if
let
Some
(
ref
var
)
=
vars
.next
()
{
let
_
=
buffer
.write
([
"'"
,
var
,
"', "
]
.concat
()
.as_bytes
());
vars
.for_each
(|
ref
var
|
{
let
_
=
buffer
.write
([
"'"
,
var
,
"' "
]
.concat
()
.as_bytes
());
});
}
let
_
=
buffer
.write
(
b"]
\n
"
);
}
else
{
let
_
=
buffer
.write
([
"'"
,
&
array
[
0
],
"' ]
\n
"
]
.concat
()
.as_bytes
());
}
}
// Write all the string variables to the buffer.
let
_
=
buffer
.write
(
b"# String Variables
\n
"
);
shell
.variables.variables
.iter
()
.for_each
(
|(
key
,
val
)|
println!
(
"{} = {}"
,
key
,
val
)
|(
key
,
val
)|
{
let
_
=
buffer
.write
([
key
,
" = "
,
val
.as_str
(),
"
\n
"
]
.concat
()
.as_bytes
());
}
);
// Then immediately follow that with a list of array variables.
let
_
=
buffer
.write
(
b"
\n
# Array Variables
\n
"
);
shell
.variables.arrays
.iter
()
.for_each
(
|(
key
,
val
)|
print_array
(
&
mut
buffer
,
&
key
,
&
val
)
);
SUCCESS
}
...
...
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