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
f9d24907
Verified
Commit
f9d24907
authored
1 year ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
fish completion done
parent
14ab635b
No related branches found
No related tags found
No related merge requests found
Pipeline
#29386
passed
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
+50
-10
50 additions, 10 deletions
NodeApp/src/helpers/AutoCompletionHelper.ts
with
50 additions
and
10 deletions
NodeApp/src/helpers/AutoCompletionHelper.ts
+
50
−
10
View file @
f9d24907
...
...
@@ -23,6 +23,17 @@ function isLeaf(cmd: Command): boolean {
return
cmd
.
commands
.
length
==
0
}
function
flatten
(
cmd
:
Command
):
Array
<
Command
>
{
if
(
isLeaf
(
cmd
))
{
return
[
cmd
]
}
else
{
return
cmd
.
commands
.
map
(
child
=>
flatten
(
child
))
.
reduce
((
acc
,
cmd
)
=>
acc
.
concat
(
cmd
),
[
cmd
])
}
}
// Computes the maximum number of commands until a leaf is reached
function
computeDepth
(
cmd
:
Command
|
undefined
):
number
{
if
(
cmd
===
undefined
)
{
return
0
...
...
@@ -31,6 +42,17 @@ function computeDepth(cmd: Command | undefined): number {
}
}
// Computes the maximum number of commands until the root is reached
function
computeHeigth
(
cmd
:
Command
|
null
):
number
{
let
height
=
0
let
tmp
=
cmd
while
(
tmp
!==
null
)
{
tmp
=
tmp
.
parent
height
+=
1
}
return
height
}
function
getOptions
(
cmd
:
Command
):
string
{
// we remove <args>, [command], and , from option lines
return
cmd
.
options
.
filter
(
opt
=>
!
opt
.
hidden
).
map
(
opt
=>
...
...
@@ -93,22 +115,40 @@ export function writeBashCompletion(root: Command, filename: string) {
const
prefix
=
'
complete -f -c dojo -n
\'
__fish_dojo_using_commands
'
function
generate
FishSub
Command
s
(
cmd
:
Command
,
crtDepth
:
number
):
string
{
function
generateCommand
Chain
(
cmd
:
Command
|
null
):
string
{
let
data
=
''
for
(
const
arg
of
cmd
.
commands
)
{
data
+=
`
${
prefix
}
${
crtDepth
}
${
cmd
.
name
()}
' -a
${
arg
.
name
()}
-d "
${
arg
.
description
()}
"\n`
while
(
cmd
!==
null
)
{
data
=
cmd
.
name
().
concat
(
`
${
data
}
`
)
cmd
=
cmd
.
parent
}
return
data
return
data
.
trimEnd
()
}
export
function
writeFishCompletion
(
root
:
Command
,
filename
:
string
)
{
const
depth
=
computeDepth
(
root
)
const
commands
=
flatten
(
root
)
let
data
=
fishFunction
for
(
let
i
=
1
;
i
<=
depth
;
i
++
)
{
data
+=
generateFishSubCommands
(
root
,
i
)
let
data
=
fishFunction
// add commands and subcommands
commands
.
forEach
(
cmd
=>
{
if
(
isLeaf
(
cmd
))
{
cmd
.
options
.
forEach
(
opt
=>
{
if
(
!
opt
.
hidden
)
{
data
+=
`
${
prefix
}
${
computeHeigth
(
cmd
)}
${
generateCommandChain
(
cmd
)}
' -a "--
${
opt
.
name
()}
" -d "
${
opt
.
description
}
"\n`
}
})
}
cmd
.
commands
.
forEach
(
subCmd
=>
{
data
+=
`
${
prefix
}
${
computeHeigth
(
cmd
)}
${
generateCommandChain
(
cmd
)}
' -a
${
subCmd
.
name
()}
-d "
${
subCmd
.
description
()}
"\n`
if
(
cmd
.
options
.
length
>
0
)
{
cmd
.
options
.
forEach
(
opt
=>
{
if
(
!
opt
.
hidden
)
{
data
+=
`
${
prefix
}
${
computeHeigth
(
cmd
)}
${
generateCommandChain
(
cmd
)}
' -a "--
${
opt
.
name
()}
" -d "
${
opt
.
description
}
"\n`
}
})
}
})
})
writeFileSync
(
filename
,
data
);
}
...
...
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