mirror of
https://github.com/ddworken/hishtory.git
synced 2024-12-24 15:58:52 +01:00
Add support for forcing init without prompting via --force flag for #198
This commit is contained in:
parent
68b3311a07
commit
3589e8cf49
@ -3034,4 +3034,25 @@ func TestWebUi(t *testing.T) {
|
||||
require.Equal(t, 401, resp.StatusCode)
|
||||
}
|
||||
|
||||
func TestForceInit(t *testing.T) {
|
||||
markTestForSharding(t, 13)
|
||||
defer testutils.BackupAndRestore(t)()
|
||||
tester := zshTester{}
|
||||
initialSecret := installHishtory(t, tester, "")
|
||||
secondaryUserSecret := initialSecret + "-second"
|
||||
|
||||
// Run a commands to search for and confirm it was recorded
|
||||
tester.RunInteractiveShell(t, `echo foobar`)
|
||||
require.Equal(t, "echo foobar\n", tester.RunInteractiveShell(t, `hishtory export -pipefail -export`))
|
||||
|
||||
// Init as the other user with --force
|
||||
out, err := tester.RunInteractiveShellRelaxed(t, ` export HISHTORY_SKIP_INIT_IMPORT=1
|
||||
hishtory init --force `+secondaryUserSecret)
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, out, "Setting secret hishtory key to "+secondaryUserSecret, "Failed to re-init with the user secret")
|
||||
|
||||
// Check that the history was cleared
|
||||
require.NotContains(t, tester.RunInteractiveShell(t, `hishtory export`), "echo foobar")
|
||||
}
|
||||
|
||||
// TODO: somehow test/confirm that hishtory works even if only bash/only zsh is installed
|
||||
|
@ -24,6 +24,7 @@ import (
|
||||
)
|
||||
|
||||
var offlineInit *bool
|
||||
var forceInit *bool
|
||||
var offlineInstall *bool
|
||||
|
||||
var installCmd = &cobra.Command{
|
||||
@ -66,7 +67,7 @@ var initCmd = &cobra.Command{
|
||||
lib.CheckFatalError(err)
|
||||
count, err := lib.CountStoredEntries(db)
|
||||
lib.CheckFatalError(err)
|
||||
if count > 0 {
|
||||
if count > 0 && !(*forceInit) {
|
||||
fmt.Printf("Your current hishtory profile has saved history entries, are you sure you want to run `init` and reset?\nNote: This won't clear any imported history entries from your existing shell\n[y/N]")
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
resp, err := reader.ReadString('\n')
|
||||
@ -637,5 +638,6 @@ func init() {
|
||||
rootCmd.AddCommand(uninstallCmd)
|
||||
|
||||
offlineInit = initCmd.Flags().Bool("offline", false, "Install hiSHtory in offline mode wiht all syncing capabilities disabled")
|
||||
forceInit = initCmd.Flags().Bool("force", false, "Force re-init without any prompts")
|
||||
offlineInstall = installCmd.Flags().Bool("offline", false, "Install hiSHtory in offline mode wiht all syncing capabilities disabled")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user