Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
senf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
wiback
senf
Commits
128529c2
Commit
128529c2
authored
16 years ago
by
g0dil
Browse files
Options
Downloads
Patches
Plain Diff
Console: Fix autocomplete / autocd support
parent
60f67bfa
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Console/Executor.cc
+15
-3
15 additions, 3 deletions
Console/Executor.cc
Console/Executor.hh
+1
-0
1 addition, 0 deletions
Console/Executor.hh
Console/Executor.test.cc
+32
-0
32 additions, 0 deletions
Console/Executor.test.cc
with
48 additions
and
3 deletions
Console/Executor.cc
+
15
−
3
View file @
128529c2
...
...
@@ -249,7 +249,7 @@ senf::console::Executor::traverseNode(ParseCommandInfo::TokensRange const & path
boost
::
prior
(
path
.
end
())),
dir
);
DirectoryNode
&
base
(
*
dir
.
back
().
lock
());
std
::
string
const
&
name
(
boost
::
prior
(
path
.
end
())
->
value
());
std
::
string
const
&
name
(
complete
(
base
,
boost
::
prior
(
path
.
end
())
->
value
())
)
;
if
(
policy_
)
policy_
(
base
,
name
);
return
dir
.
back
().
lock
()
->
get
(
name
);
...
...
@@ -281,9 +281,10 @@ senf::console::Executor::traverseDirectory(ParseCommandInfo::TokensRange const &
;
else
{
DirectoryNode
&
base
(
*
dir
.
back
().
lock
());
std
::
string
name
(
complete
(
base
,
i
->
value
()));
if
(
policy_
)
policy_
(
base
,
i
->
value
()
);
dir
.
push_back
(
base
[
i
->
value
()
].
thisptr
());
policy_
(
base
,
name
);
dir
.
push_back
(
base
[
name
].
thisptr
());
}
}
}
...
...
@@ -295,6 +296,17 @@ senf::console::Executor::traverseDirectory(ParseCommandInfo::TokensRange const &
}
}
prefix_
std
::
string
senf
::
console
::
Executor
::
complete
(
DirectoryNode
&
dir
,
std
::
string
const
&
name
)
{
if
(
!
dir
.
hasChild
(
name
))
{
DirectoryNode
::
ChildrenRange
completions
(
dir
.
completions
(
name
));
if
(
completions
.
size
()
==
1
)
return
completions
.
begin
()
->
first
;
}
return
name
;
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "Executor.mpp"
...
...
This diff is collapsed.
Click to expand it.
Console/Executor.hh
+
1
−
0
View file @
128529c2
...
...
@@ -145,6 +145,7 @@ namespace console {
GenericNode
&
traverseNode
(
ParseCommandInfo
::
TokensRange
const
&
path
);
void
traverseDirectory
(
ParseCommandInfo
::
TokensRange
const
&
path
,
Path
&
dir
);
std
::
string
complete
(
DirectoryNode
&
dir
,
std
::
string
const
&
name
);
struct
InvalidPathException
{};
struct
InvalidDirectoryException
{};
...
...
This diff is collapsed.
Click to expand it.
Console/Executor.test.cc
+
32
−
0
View file @
128529c2
...
...
@@ -229,6 +229,38 @@ BOOST_AUTO_UNIT_TEST(executorPolicy)
senf
::
console
::
root
().
remove
(
"dir2"
);
}
BOOST_AUTO_UNIT_TEST
(
executorAuto
)
{
senf
::
console
::
root
().
mkdir
(
"dir1"
).
mkdir
(
"dir3"
);
senf
::
console
::
root
().
mkdir
(
"dir2"
).
doc
(
"Helptext"
).
add
(
"test"
,
&
testCommand
);
senf
::
console
::
Executor
executor
;
executor
.
autocomplete
(
true
)
.
autocd
(
true
);
senf
::
console
::
CommandParser
parser
;
{
std
::
stringstream
os
;
parser
.
parse
(
"dir2"
,
&
setCommand
);
executor
(
os
,
commands
.
back
());
BOOST_CHECK_EQUAL
(
executor
.
cwdPath
(),
"/dir2"
);
BOOST_CHECK_EQUAL
(
os
.
str
(),
""
);
}
{
std
::
stringstream
os
;
parser
.
parse
(
"t"
,
&
setCommand
);
executor
(
os
,
commands
.
back
());
BOOST_CHECK_EQUAL
(
os
.
str
(),
"testCommand
\n
"
);
}
commands
.
clear
();
senf
::
console
::
root
().
remove
(
"dir1"
);
senf
::
console
::
root
().
remove
(
"dir2"
);
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
...
...
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