Add help command

This commit is contained in:
David Dworken 2022-06-05 18:26:02 -07:00
parent 5e44e7ef36
commit ad7e412855
2 changed files with 42 additions and 0 deletions

View File

@ -124,6 +124,7 @@ func TestParameterized(t *testing.T) {
t.Run("testRequestAndReceiveDbDump/"+tester.ShellName(), func(t *testing.T) { testRequestAndReceiveDbDump(t, tester) })
t.Run("testInstallViaPythonScript/"+tester.ShellName(), func(t *testing.T) { testInstallViaPythonScript(t, tester) })
t.Run("testExportWithQuery/"+tester.ShellName(), func(t *testing.T) { testExportWithQuery(t, tester) })
t.Run("testHelpCommand/"+tester.ShellName(), func(t *testing.T) { testHelpCommand(t, tester) })
}
}
@ -1125,4 +1126,20 @@ echo thisisrecorded`)
}
}
func testHelpCommand(t *testing.T, tester shellTester) {
// Setup
defer shared.BackupAndRestore(t)()
installHishtory(t, tester, "")
// Test the help command
out := tester.RunInteractiveShell(t, `hishtory help`)
if !strings.HasPrefix(out, "hishtory: Better shell history\n\nSupported commands:\n") {
t.Fatalf("expected hishtory help to contain intro, actual=%#v", out)
}
out2 := tester.RunInteractiveShell(t, `hishtory -h`)
if out != out2 {
t.Fatalf("expected hishtory -h to equal help")
}
}
// TODO: write a test that runs hishtroy export | grep -v pipefail and then see if that shows up in query/export, I think there is weird behavior here

View File

@ -51,6 +51,31 @@ func main() {
fmt.Printf("Commit Hash: %s\n", GitCommit)
case "update":
lib.CheckFatalError(lib.Update())
case "-h":
fallthrough
case "help":
fmt.Print(`hishtory: Better shell history
Supported commands:
'hishtory query': Query for matching commands and display them in a table. Examples:
'hishtory query apt-get' # Find shell commands containing 'apt-get'
'hishtory query apt-get install' # Find shell commands containing 'apt-get' and 'install'
'hishtory query curl cwd:/tmp/' # Find shell commands containing 'curl' run in '/tmp/'
'hishtory query curl user:david' # Find shell commands containing 'curl' run by 'david'
'hishtory query curl host:x1' # Find shell commands containing 'curl' run on 'x1'
'hishtory query exit_code:1' # Find shell commands that exited with status code 1
'hishtory query before:2022-02-01' # Find shell commands run before 2022-02-01
'hishtory export': Query for matching commands and display them in list without any other
metadata. Supports the same query format as 'hishtory query'.
'hishtory update': Securely update hishtory to the latest version.
'hishtory disable': Stop recording shell commands
'hishtory enable': Start recording shell commands
'hishtory status': View status info including the secret key which is needed to sync shell
history from another machine.
'hishtory init': Set the secret key to enable syncing shell commands from another
machine with a matching secret key.
'hishtory help': View this help page
`)
default:
lib.CheckFatalError(fmt.Errorf("unknown command: %s", os.Args[1]))
}