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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dojo Project (HES-SO)
Projects
UI
DojoCLI
Commits
59b89b5d
Verified
Commit
59b89b5d
authored
1 year ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
started working of fish completion
parent
8d09a116
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
NodeApp/src/commander/CommanderApp.ts
+2
-1
2 additions, 1 deletion
NodeApp/src/commander/CommanderApp.ts
NodeApp/src/helpers/AutoCompletionHelper.ts
+50
-0
50 additions, 0 deletions
NodeApp/src/helpers/AutoCompletionHelper.ts
with
52 additions
and
1 deletion
NodeApp/src/commander/CommanderApp.ts
+
2
−
1
View file @
59b89b5d
...
...
@@ -9,7 +9,7 @@ import { stateConfigFile } from '../config/ConfigFiles';
import
semver
from
'
semver/preload
'
;
import
{
version
}
from
'
../config/Version
'
;
import
Config
from
'
../config/Config
'
;
import
{
getBashCompletion
}
from
'
../helpers/AutoCompletionHelper
'
;
import
{
getBashCompletion
,
getFishCompletion
}
from
'
../helpers/AutoCompletionHelper
'
;
class
CommanderApp
{
...
...
@@ -45,6 +45,7 @@ class CommanderApp {
this
.
registerCommands
();
getBashCompletion
(
this
.
program
,
"
bash_completion.sh
"
)
getFishCompletion
(
this
.
program
,
"
dojo.fish
"
)
this
.
program
.
parse
();
}
...
...
This diff is collapsed.
Click to expand it.
NodeApp/src/helpers/AutoCompletionHelper.ts
+
50
−
0
View file @
59b89b5d
...
...
@@ -97,6 +97,10 @@ function isLeaf(tree: CmdNode): boolean {
return
tree
.
children
===
undefined
||
tree
.
children
.
length
==
0
}
function
isRoot
(
tree
:
CmdNode
):
boolean
{
return
tree
.
parent
===
undefined
}
function
search
(
tree
:
CmdNode
,
cmdName
:
string
):
Array
<
CmdNode
>
{
if
(
isLeaf
(
tree
))
{
if
(
tree
.
name
!=
cmdName
)
{
...
...
@@ -173,6 +177,52 @@ function addLine(identLevel: number, pattern: string): string {
return
`
${
'
'
.
repeat
(
identLevel
)}${
pattern
}
\n`
}
const
fishFunctions
=
`### Fish completions for dojo ###
function __fish_dojo_needs_command
set cmd (commandline -opc)
if [ (count $cmd) -eq 1 -a $cmd[1] = dojo ]
return 0
end
return 1
end
function __fish_dojo_using_command
set cmd (commandline -opc)
set num_cmd (count $cmd)
if [ $num_cmd -eq 2 ]
if [ $argv[(math $num_cmd - 1)] = $cmd[$num_cmd] ]
return 0
end
end
return 1
end
function __fish_dojo_using_two_commands
set cmd (commandline -opc)
set num_cmd (count $cmd)
if [ $num_cmd -gt 3 ]
if [ $argv[(math $num_cmd - 2)] = $cmd[(math $num_cmd - 1)] -a $argv[(math $num_cmd - 1)] = $cmd[$num_cmd] ]
return 0
end
end
return 1
end
`
export
function
getFishCompletion
(
root
:
Command
,
filename
:
string
)
{
const
tree
=
buildCmdNode
(
root
)
const
commands
=
Array
.
from
(
new
Set
(
flatten
(
tree
).
filter
(
cmd
=>
!
isLeaf
(
cmd
)).
map
(
cmd
=>
cmd
.
name
))).
map
(
name
=>
search
(
tree
,
name
))
let
data
=
fishFunctions
for
(
const
node
of
commands
)
{
const
cmd
=
node
[
0
]
data
+=
addLine
(
0
,
`complete -f -c dojo -n __fish_dojo_needs_command
${
cmd
.
name
}
-a "
${
cmd
.
children
.
map
(
c
=>
c
.
name
).
join
(
"
"
)}
--help -h"`
)
}
writeFileSync
(
filename
,
data
);
}
export
function
getBashCompletion
(
root
:
Command
,
filename
:
string
)
{
const
tree
=
buildCmdNode
(
root
)
...
...
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