Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
goSDN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor 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
danet
goSDN
Commits
801bf97b
Commit
801bf97b
authored
2 years ago
by
Malte Bauch
Browse files
Options
Downloads
Patches
Plain Diff
Rename device to network element in cli.prompt
parent
d1058091
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!410
Some basic house keeping
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cli/cmd/prompt.go
+17
-18
17 additions, 18 deletions
cli/cmd/prompt.go
with
17 additions
and
18 deletions
cli/cmd/prompt.go
+
17
−
18
View file @
801bf97b
...
@@ -46,7 +46,7 @@ import (
...
@@ -46,7 +46,7 @@ import (
"github.com/spf13/viper"
"github.com/spf13/viper"
)
)
// PromptCompleter provides completion for a
device
.
// PromptCompleter provides completion for a
Network Element
.
type
PromptCompleter
struct
{
type
PromptCompleter
struct
{
yangSchemaCompleterMap
map
[
uuid
.
UUID
]
*
completer
.
YangSchemaCompleter
yangSchemaCompleterMap
map
[
uuid
.
UUID
]
*
completer
.
YangSchemaCompleter
currentSuggestions
[]
prompt
.
Suggest
currentSuggestions
[]
prompt
.
Suggest
...
@@ -132,19 +132,19 @@ func filterFlagSlice(input []string) (commandSlice []string, flagSlice []string)
...
@@ -132,19 +132,19 @@ func filterFlagSlice(input []string) (commandSlice []string, flagSlice []string)
return
commandSlice
,
flagSlice
return
commandSlice
,
flagSlice
}
}
func
device
GetCompletion
(
c
*
PromptCompleter
,
d
prompt
.
Document
,
inputSplit
[]
string
)
[]
prompt
.
Suggest
{
func
networkElement
GetCompletion
(
c
*
PromptCompleter
,
d
prompt
.
Document
,
inputSplit
[]
string
)
[]
prompt
.
Suggest
{
switch
inputLen
:=
len
(
inputSplit
);
inputLen
{
switch
inputLen
:=
len
(
inputSplit
);
inputLen
{
case
2
:
case
2
:
return
c
.
updateSuggestionsThroughFunc
(
d
,
get
Device
s
)
return
c
.
updateSuggestionsThroughFunc
(
d
,
get
NetworkElement
s
)
case
3
:
case
3
:
id
,
err
:=
uuid
.
Parse
(
inputSplit
[
inputLen
-
1
])
id
,
err
:=
uuid
.
Parse
(
inputSplit
[
inputLen
-
1
])
if
err
!=
nil
{
if
err
!=
nil
{
return
c
.
updateSuggestionsThroughFunc
(
d
,
get
Device
s
)
return
c
.
updateSuggestionsThroughFunc
(
d
,
get
NetworkElement
s
)
}
}
if
c
,
ok
:=
c
.
yangSchemaCompleterMap
[
id
];
ok
{
if
c
,
ok
:=
c
.
yangSchemaCompleterMap
[
id
];
ok
{
return
c
.
Complete
(
d
)
return
c
.
Complete
(
d
)
}
}
schemaTree
,
err
:=
getSchemaTreeFor
Device
ID
(
id
.
String
())
schemaTree
,
err
:=
getSchemaTreeFor
NetworkElement
ID
(
id
.
String
())
if
err
!=
nil
{
if
err
!=
nil
{
return
[]
prompt
.
Suggest
{}
return
[]
prompt
.
Suggest
{}
}
}
...
@@ -158,7 +158,7 @@ func deviceGetCompletion(c *PromptCompleter, d prompt.Document, inputSplit []str
...
@@ -158,7 +158,7 @@ func deviceGetCompletion(c *PromptCompleter, d prompt.Document, inputSplit []str
}
}
id
,
err
:=
uuid
.
Parse
(
inputSplit
[
inputLen
-
2
])
id
,
err
:=
uuid
.
Parse
(
inputSplit
[
inputLen
-
2
])
if
err
!=
nil
{
if
err
!=
nil
{
return
c
.
updateSuggestionsThroughFunc
(
d
,
get
Device
s
)
return
c
.
updateSuggestionsThroughFunc
(
d
,
get
NetworkElement
s
)
}
}
if
yc
,
ok
:=
c
.
yangSchemaCompleterMap
[
id
];
ok
{
if
yc
,
ok
:=
c
.
yangSchemaCompleterMap
[
id
];
ok
{
return
yc
.
Complete
(
d
)
return
yc
.
Complete
(
d
)
...
@@ -216,16 +216,16 @@ func completionBasedOnCmd(c *PromptCompleter, cmd *cobra.Command, inputSplit []s
...
@@ -216,16 +216,16 @@ func completionBasedOnCmd(c *PromptCompleter, cmd *cobra.Command, inputSplit []s
}
}
case
networkElementRemoveCmd
:
case
networkElementRemoveCmd
:
if
len
(
inputSplit
)
<
3
||
(
len
(
inputSplit
)
==
3
&&
d
.
GetWordBeforeCursor
()
!=
""
)
{
if
len
(
inputSplit
)
<
3
||
(
len
(
inputSplit
)
==
3
&&
d
.
GetWordBeforeCursor
()
!=
""
)
{
return
c
.
updateSuggestionsThroughFunc
(
d
,
get
Device
s
)
return
c
.
updateSuggestionsThroughFunc
(
d
,
get
NetworkElement
s
)
}
}
case
networkElementGetCmd
,
networkElementSetCmd
:
case
networkElementGetCmd
,
networkElementSetCmd
:
return
device
GetCompletion
(
c
,
d
,
inputSplit
)
return
networkElement
GetCompletion
(
c
,
d
,
inputSplit
)
case
networkElementShowCmd
:
case
networkElementShowCmd
:
devices
,
err
:=
getDevice
s
()
networkElements
,
err
:=
getNetworkElement
s
()
if
err
!=
nil
{
if
err
!=
nil
{
return
[]
prompt
.
Suggest
{}
return
[]
prompt
.
Suggest
{}
}
}
return
device
s
return
networkElement
s
case
networkElementCmd
,
pndCmd
,
changeCmd
:
case
networkElementCmd
,
pndCmd
,
changeCmd
:
c
.
currentSuggestions
=
nil
c
.
currentSuggestions
=
nil
return
cobraCommandCompletion
(
cmd
,
d
,
inputFlags
,
[]
prompt
.
Suggest
{})
return
cobraCommandCompletion
(
cmd
,
d
,
inputFlags
,
[]
prompt
.
Suggest
{})
...
@@ -236,11 +236,11 @@ func completionBasedOnCmd(c *PromptCompleter, cmd *cobra.Command, inputSplit []s
...
@@ -236,11 +236,11 @@ func completionBasedOnCmd(c *PromptCompleter, cmd *cobra.Command, inputSplit []s
return
[]
prompt
.
Suggest
{}
return
[]
prompt
.
Suggest
{}
}
}
// get
Device
s is a helper function which requests
device
s from the controller
// get
NetworkElement
s is a helper function which requests
Network Element
s from the controller
// and gives feedback about the current pulling status with the help of pterm
// and gives feedback about the current pulling status with the help of pterm
// the result is converted into a prompt.Suggest slice.
// the result is converted into a prompt.Suggest slice.
func
get
Device
s
()
([]
prompt
.
Suggest
,
error
)
{
func
get
NetworkElement
s
()
([]
prompt
.
Suggest
,
error
)
{
spinner
,
_
:=
pterm
.
DefaultSpinner
.
Start
(
"Fetching
device
s from controller."
)
spinner
,
_
:=
pterm
.
DefaultSpinner
.
Start
(
"Fetching
Network Element
s from controller."
)
resp
,
err
:=
pndAdapter
.
GetFlattenedNetworkElements
(
createContextWithAuthorization
())
resp
,
err
:=
pndAdapter
.
GetFlattenedNetworkElements
(
createContextWithAuthorization
())
if
err
!=
nil
{
if
err
!=
nil
{
spinner
.
Fail
(
err
)
spinner
.
Fail
(
err
)
...
@@ -255,11 +255,11 @@ func getDevices() ([]prompt.Suggest, error) {
...
@@ -255,11 +255,11 @@ func getDevices() ([]prompt.Suggest, error) {
return
completer
.
SortSuggestionByText
(
s
),
nil
return
completer
.
SortSuggestionByText
(
s
),
nil
}
}
// getSchemaTreeFor
Device
ID is a helper function which requests the SBI's
// getSchemaTreeFor
NetworkElement
ID is a helper function which requests the SBI's
// schema tree of a specific
device
. The function gives feedback about the
// schema tree of a specific
Network Element
. The function gives feedback about the
// current pulling status with the help of pterm.
// current pulling status with the help of pterm.
func
getSchemaTreeFor
Device
ID
(
id
string
)
(
map
[
string
]
*
yang
.
Entry
,
error
)
{
func
getSchemaTreeFor
NetworkElement
ID
(
id
string
)
(
map
[
string
]
*
yang
.
Entry
,
error
)
{
spinner
,
_
:=
pterm
.
DefaultSpinner
.
Start
(
"Fetching schema tree for
Device
with ID: "
,
id
)
spinner
,
_
:=
pterm
.
DefaultSpinner
.
Start
(
"Fetching schema tree for
Network Element
with ID: "
,
id
)
dev
,
err
:=
pndAdapter
.
GetNetworkElement
(
createContextWithAuthorization
(),
id
)
dev
,
err
:=
pndAdapter
.
GetNetworkElement
(
createContextWithAuthorization
(),
id
)
if
err
!=
nil
{
if
err
!=
nil
{
spinner
.
Fail
(
err
)
spinner
.
Fail
(
err
)
...
@@ -347,7 +347,6 @@ var exitCmd = &cobra.Command{
...
@@ -347,7 +347,6 @@ var exitCmd = &cobra.Command{
},
},
}
}
// deviceListCmd represents the listDevice command.
var
promptCmd
=
&
cobra
.
Command
{
var
promptCmd
=
&
cobra
.
Command
{
Use
:
"prompt"
,
Use
:
"prompt"
,
Short
:
"The prompt command runs the CLI in an interactive shell."
,
Short
:
"The prompt command runs the CLI in an interactive shell."
,
...
...
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