Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DojoCLI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Dojo Project (HES-SO)
Projects
UI
DojoCLI
Commits
bab27e23
Verified
Commit
bab27e23
authored
1 year ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
added tree
parent
c1d910ad
No related branches found
No related tags found
1 merge request
!8
Draft: Resolve "Add bash completion helper function"
Pipeline
#29315
failed
1 year ago
Stage: code_quality
Stage: test
Changes
1
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
NodeApp/src/helpers/AutoCompletionHelper.ts
+71
-9
71 additions, 9 deletions
NodeApp/src/helpers/AutoCompletionHelper.ts
with
71 additions
and
9 deletions
NodeApp/src/helpers/AutoCompletionHelper.ts
+
71
−
9
View file @
bab27e23
import
{
Options
}
from
'
boxen
'
;
import
{
Command
}
from
'
commander
'
;
import
{
writeFileSync
}
from
'
fs
'
;
// #/usr/bin/env bash
...
...
@@ -39,15 +39,17 @@ import { writeFileSync } from 'fs';
// }
// complete -F _dojo_completions dojo
// class NodeTree {
// parent: NodeTree | null;
// name: string;
class
Tree
{
name
:
string
;
parent
?:
string
;
children
:
Array
<
Tree
>
;
// constructor(parent: NodeTree | null, name: string) {
// this.parent = parent;
// this.name = name;
// }
// }
constructor
(
name
:
string
,
children
:
Array
<
Tree
>
,
parent
?:
string
)
{
this
.
name
=
name
;
this
.
children
=
children
;
this
.
parent
=
parent
;
}
}
class
AutoCompletionHelper
{
...
...
@@ -104,6 +106,66 @@ class AutoCompletionHelper {
console
.
log
(
"
complete -F _dojo_completions dojo
"
)
}
private
isLeaf
(
tree
:
Tree
):
boolean
{
return
tree
.
children
===
undefined
||
tree
.
children
.
length
==
0
}
private
getOptions
(
cmd
:
Command
):
Array
<
Tree
>
{
return
cmd
.
options
.
map
(
o
=>
new
Tree
(
"
--
"
+
o
.
name
(),
[],
cmd
.
name
()))
}
private
getSubTree
(
cmd
:
Command
,
parent
:
Command
):
Tree
{
// let words = []
if
(
cmd
.
commands
.
length
>
0
)
{
return
new
Tree
(
cmd
.
name
(),
cmd
.
commands
.
map
((
sc
)
=>
this
.
getSubTree
(
sc
,
cmd
)).
concat
(
this
.
getOptions
(
cmd
)),
parent
.
name
())
}
else
{
return
new
Tree
(
cmd
.
name
(),
this
.
getOptions
(
cmd
),
parent
.
name
())
}
}
private
printTree
(
tree
:
Tree
,
i
:
number
)
{
if
(
!
this
.
isLeaf
(
tree
))
{
tree
.
children
.
map
((
c
)
=>
this
.
printTree
(
c
,
i
+
4
))
console
.
log
(
"
"
.
repeat
(
i
)
+
tree
.
name
)
}
else
{
console
.
log
(
"
"
.
repeat
(
i
)
+
tree
.
name
)
}
}
private
search
(
tree
:
Tree
,
nodes
:
Array
<
Tree
>
,
cmdName
:
string
):
Array
<
Tree
>
{
if
(
this
.
isLeaf
(
tree
))
{
if
(
tree
.
name
!=
cmdName
)
{
return
nodes
}
else
{
return
nodes
.
concat
(
tree
)
}
}
else
if
(
tree
.
name
==
cmdName
)
{
return
tree
.
children
.
flatMap
(
st
=>
this
.
search
(
st
,
nodes
,
cmdName
)).
concat
(
tree
)
}
else
{
return
tree
.
children
.
flatMap
(
st
=>
this
.
search
(
st
,
nodes
,
cmdName
))
}
}
flatten
(
tree
:
Tree
):
string
[]
{
if
(
this
.
isLeaf
(
tree
))
{
return
[
tree
.
name
]
}
else
{
return
tree
.
children
.
map
(
c
=>
this
.
flatten
(
c
)
)
.
reduce
((
acc
,
n
)
=>
acc
.
concat
(
n
),
[
tree
.
name
])
}
}
buildTree
(
root
:
Command
):
Tree
{
let
tree
=
new
Tree
(
root
.
name
(),
root
.
commands
.
map
((
sc
)
=>
this
.
getSubTree
(
sc
,
root
)))
this
.
printTree
(
tree
,
0
)
console
.
log
(
this
.
flatten
(
tree
))
console
.
log
(
this
.
search
(
tree
,
[],
"
login
"
))
return
tree
}
}
export
default
new
AutoCompletionHelper
();
\ No newline at end of file
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