Skip to content

Commit

Permalink
Merge pull request #24 from Apcela/reset_state_command
Browse files Browse the repository at this point in the history
Reset state command
  • Loading branch information
lykinsbd authored Feb 4, 2021
2 parents 12c936a + 9de0ada commit c0a6be5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions fakedevices/genericFakeDevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type FakeDevice struct {
Vendor string // Vendor of this fake device
Platform string // Platform of this fake device
Hostname string // Hostname of the fake device
DefaultHostname string // Default Hostname of the fake device (for resetting)
Password string // Password of the fake device
SupportedCommands SupportedCommands // What commands this fake device supports
ContextSearch map[string]string // The available CLI prompt/contexts on this fake device
Expand Down Expand Up @@ -70,6 +71,7 @@ func InitGeneric(
Vendor: vendor,
Platform: platform,
Hostname: deviceHostname,
DefaultHostname: deviceHostname,
Password: devicePassword,
SupportedCommands: supportedCommands,
ContextSearch: contextSearch,
Expand Down
10 changes: 9 additions & 1 deletion ssh_server/handlers/ciscohandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ func GenericCiscoHandler(myFakeDevice *fakedevices.FakeDevice) {
ContextState = myFakeDevice.ContextHierarchy[ContextState]
continue
}
} else if userInput == "reset state" {
term.Write(append([]byte("Resetting State..."), '\n'))
ContextState = myFakeDevice.ContextSearch["base"]
myFakeDevice.Hostname = myFakeDevice.DefaultHostname
term.SetPrompt(string(
myFakeDevice.Hostname + ContextState,
))
continue
}

// Split user input into fields
Expand Down Expand Up @@ -108,7 +116,7 @@ func GenericCiscoHandler(myFakeDevice *fakedevices.FakeDevice) {
continue
} else {
// If all else fails, we did not recognize the input!
term.Write(append([]byte("% Ambiguous command: \""+userInput+"\""), '\n'))
term.Write(append([]byte("% Unknown command: \""+userInput+"\""), '\n'))
continue
}
}
Expand Down

0 comments on commit c0a6be5

Please sign in to comment.