mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-24 22:11:40 +02:00
Disable flag parsing for the querying functions so they can use exclusions + refactor redact to remove the --force flag
This commit is contained in:
parent
6ef9bb00d5
commit
0667494239
@ -1531,27 +1531,27 @@ ls /tmp`, randomCmdUuid, randomCmdUuid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Redact foo
|
// Redact foo
|
||||||
out = tester.RunInteractiveShell(t, `hishtory redact --force foo`)
|
out = tester.RunInteractiveShell(t, `HISHTORY_REDACT_FORCE=1 hishtory redact foo`)
|
||||||
if out != "Permanently deleting 2 entries\n" {
|
if out != "Permanently deleting 2 entries\n" {
|
||||||
t.Fatalf("hishtory redact gave unexpected output=%#v", out)
|
t.Fatalf("hishtory redact gave unexpected output=%#v", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the commands are redacted
|
// Check that the commands are redacted
|
||||||
out = tester.RunInteractiveShell(t, `hishtory export | grep -v pipefail`)
|
out = tester.RunInteractiveShell(t, `hishtory export | grep -v pipefail`)
|
||||||
expectedOutput = fmt.Sprintf("echo %s-bas\nls /tmp\nhishtory redact --force foo\n", randomCmdUuid)
|
expectedOutput = fmt.Sprintf("echo %s-bas\nls /tmp\nHISHTORY_REDACT_FORCE=1 hishtory redact foo\n", randomCmdUuid)
|
||||||
if diff := cmp.Diff(expectedOutput, out); diff != "" {
|
if diff := cmp.Diff(expectedOutput, out); diff != "" {
|
||||||
t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
|
t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redact s
|
// Redact s
|
||||||
out = tester.RunInteractiveShell(t, `hishtory redact --force s`)
|
out = tester.RunInteractiveShell(t, `HISHTORY_REDACT_FORCE=1 hishtory redact s`)
|
||||||
if out != "Permanently deleting 10 entries\n" && out != "Permanently deleting 11 entries\n" {
|
if out != "Permanently deleting 10 entries\n" && out != "Permanently deleting 11 entries\n" {
|
||||||
t.Fatalf("hishtory redact gave unexpected output=%#v", out)
|
t.Fatalf("hishtory redact gave unexpected output=%#v", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the commands are redacted
|
// Check that the commands are redacted
|
||||||
out = tester.RunInteractiveShell(t, `hishtory export | grep -v pipefail`)
|
out = tester.RunInteractiveShell(t, `hishtory export | grep -v pipefail`)
|
||||||
expectedOutput = "hishtory redact --force s\n"
|
expectedOutput = "HISHTORY_REDACT_FORCE=1 hishtory redact s\n"
|
||||||
if diff := cmp.Diff(expectedOutput, out); diff != "" {
|
if diff := cmp.Diff(expectedOutput, out); diff != "" {
|
||||||
t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
|
t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
|
||||||
}
|
}
|
||||||
@ -1559,12 +1559,12 @@ ls /tmp`, randomCmdUuid, randomCmdUuid)
|
|||||||
// Record another command
|
// Record another command
|
||||||
tester.RunInteractiveShell(t, `echo hello`)
|
tester.RunInteractiveShell(t, `echo hello`)
|
||||||
out = tester.RunInteractiveShell(t, `hishtory export | grep -v pipefail`)
|
out = tester.RunInteractiveShell(t, `hishtory export | grep -v pipefail`)
|
||||||
expectedOutput = "hishtory redact --force s\necho hello\n"
|
expectedOutput = "HISHTORY_REDACT_FORCE=1 hishtory redact s\necho hello\n"
|
||||||
if diff := cmp.Diff(expectedOutput, out); diff != "" {
|
if diff := cmp.Diff(expectedOutput, out); diff != "" {
|
||||||
t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
|
t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redact it without --force
|
// Redact it without HISHTORY_REDACT_FORCE
|
||||||
out, err := tester.RunInteractiveShellRelaxed(t, `yes | hishtory redact hello`)
|
out, err := tester.RunInteractiveShellRelaxed(t, `yes | hishtory redact hello`)
|
||||||
testutils.Check(t, err)
|
testutils.Check(t, err)
|
||||||
if out != "This will permanently delete 1 entries, are you sure? [y/N]" {
|
if out != "This will permanently delete 1 entries, are you sure? [y/N]" {
|
||||||
@ -1573,7 +1573,7 @@ ls /tmp`, randomCmdUuid, randomCmdUuid)
|
|||||||
|
|
||||||
// And check it was redacted
|
// And check it was redacted
|
||||||
out = tester.RunInteractiveShell(t, `hishtory export | grep -v pipefail`)
|
out = tester.RunInteractiveShell(t, `hishtory export | grep -v pipefail`)
|
||||||
expectedOutput = "hishtory redact --force s\nyes | hishtory redact hello\n"
|
expectedOutput = "HISHTORY_REDACT_FORCE=1 hishtory redact s\nyes | hishtory redact hello\n"
|
||||||
if diff := cmp.Diff(expectedOutput, out); diff != "" {
|
if diff := cmp.Diff(expectedOutput, out); diff != "" {
|
||||||
t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
|
t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
|
||||||
}
|
}
|
||||||
@ -1614,14 +1614,14 @@ ls /tmp`, randomCmdUuid, randomCmdUuid)
|
|||||||
// Restore the first client, and redact some commands
|
// Restore the first client, and redact some commands
|
||||||
restoreInstall2 := testutils.BackupAndRestoreWithId(t, "-2")
|
restoreInstall2 := testutils.BackupAndRestoreWithId(t, "-2")
|
||||||
restoreInstall1()
|
restoreInstall1()
|
||||||
out = tester.RunInteractiveShell(t, `hishtory redact --force `+randomCmdUuid)
|
out = tester.RunInteractiveShell(t, `HISHTORY_REDACT_FORCE=1 hishtory redact `+randomCmdUuid)
|
||||||
if out != "Permanently deleting 2 entries\n" {
|
if out != "Permanently deleting 2 entries\n" {
|
||||||
t.Fatalf("hishtory redact gave unexpected output=%#v", out)
|
t.Fatalf("hishtory redact gave unexpected output=%#v", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Confirm that client1 doesn't have the commands
|
// Confirm that client1 doesn't have the commands
|
||||||
out = tester.RunInteractiveShell(t, `hishtory export | grep -v pipefail`)
|
out = tester.RunInteractiveShell(t, `hishtory export | grep -v pipefail`)
|
||||||
expectedOutput = fmt.Sprintf("echo foo\nls /tmp\nhishtory redact --force %s\n", randomCmdUuid)
|
expectedOutput = fmt.Sprintf("echo foo\nls /tmp\nHISHTORY_REDACT_FORCE=1 hishtory redact %s\n", randomCmdUuid)
|
||||||
if diff := cmp.Diff(expectedOutput, out); diff != "" {
|
if diff := cmp.Diff(expectedOutput, out); diff != "" {
|
||||||
t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
|
t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
|
||||||
}
|
}
|
||||||
@ -2413,7 +2413,7 @@ func fuzzTest(t *testing.T, tester shellTester, input string) {
|
|||||||
testutils.Check(t, err)
|
testutils.Check(t, err)
|
||||||
}
|
}
|
||||||
if op.redactQuery != "" {
|
if op.redactQuery != "" {
|
||||||
_, err := tester.RunInteractiveShellRelaxed(t, `hishtory redact --force `+op.redactQuery)
|
_, err := tester.RunInteractiveShellRelaxed(t, `HISHTORY_REDACT_FORCE=1 hishtory redact `+op.redactQuery)
|
||||||
testutils.Check(t, err)
|
testutils.Check(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2436,7 +2436,7 @@ func fuzzTest(t *testing.T, tester shellTester, input string) {
|
|||||||
filteredLines = append(filteredLines, line)
|
filteredLines = append(filteredLines, line)
|
||||||
}
|
}
|
||||||
val = strings.Join(filteredLines, "\n")
|
val = strings.Join(filteredLines, "\n")
|
||||||
val += `hishtory redact --force ` + op.redactQuery + "\n"
|
val += `HISHTORY_REDACT_FORCE=1 hishtory redact ` + op.redactQuery + "\n"
|
||||||
}
|
}
|
||||||
keyToCommands[op.device.key] = val
|
keyToCommands[op.device.key] = val
|
||||||
|
|
||||||
|
@ -24,10 +24,11 @@ var EXAMPLE_QUERIES string = `Example queries:
|
|||||||
var GROUP_ID_QUERYING string = "group_id:querying"
|
var GROUP_ID_QUERYING string = "group_id:querying"
|
||||||
|
|
||||||
var queryCmd = &cobra.Command{
|
var queryCmd = &cobra.Command{
|
||||||
Use: "query",
|
Use: "query",
|
||||||
Short: "Query your shell history and display the results in an ASCII art table",
|
Short: "Query your shell history and display the results in an ASCII art table",
|
||||||
GroupID: GROUP_ID_QUERYING,
|
GroupID: GROUP_ID_QUERYING,
|
||||||
Long: strings.ReplaceAll(EXAMPLE_QUERIES, "SUBCOMMAND", "query"),
|
Long: strings.ReplaceAll(EXAMPLE_QUERIES, "SUBCOMMAND", "query"),
|
||||||
|
DisableFlagParsing: true,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
ctx := hctx.MakeContext()
|
ctx := hctx.MakeContext()
|
||||||
lib.CheckFatalError(lib.ProcessDeletionRequests(ctx))
|
lib.CheckFatalError(lib.ProcessDeletionRequests(ctx))
|
||||||
@ -36,10 +37,11 @@ var queryCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var tqueryCmd = &cobra.Command{
|
var tqueryCmd = &cobra.Command{
|
||||||
Use: "tquery",
|
Use: "tquery",
|
||||||
Short: "Interactively query your shell history in a TUI interface",
|
Short: "Interactively query your shell history in a TUI interface",
|
||||||
GroupID: GROUP_ID_QUERYING,
|
GroupID: GROUP_ID_QUERYING,
|
||||||
Long: strings.ReplaceAll(EXAMPLE_QUERIES, "SUBCOMMAND", "tquery"),
|
Long: strings.ReplaceAll(EXAMPLE_QUERIES, "SUBCOMMAND", "tquery"),
|
||||||
|
DisableFlagParsing: true,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
ctx := hctx.MakeContext()
|
ctx := hctx.MakeContext()
|
||||||
lib.CheckFatalError(lib.TuiQuery(ctx, strings.Join(args, " ")))
|
lib.CheckFatalError(lib.TuiQuery(ctx, strings.Join(args, " ")))
|
||||||
@ -47,10 +49,11 @@ var tqueryCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var exportCmd = &cobra.Command{
|
var exportCmd = &cobra.Command{
|
||||||
Use: "export",
|
Use: "export",
|
||||||
Short: "Export your shell history and display just the raw commands",
|
Short: "Export your shell history and display just the raw commands",
|
||||||
GroupID: GROUP_ID_QUERYING,
|
GroupID: GROUP_ID_QUERYING,
|
||||||
Long: strings.ReplaceAll(EXAMPLE_QUERIES, "SUBCOMMAND", "export"),
|
Long: strings.ReplaceAll(EXAMPLE_QUERIES, "SUBCOMMAND", "export"),
|
||||||
|
DisableFlagParsing: true,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
ctx := hctx.MakeContext()
|
ctx := hctx.MakeContext()
|
||||||
lib.CheckFatalError(lib.ProcessDeletionRequests(ctx))
|
lib.CheckFatalError(lib.ProcessDeletionRequests(ctx))
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ddworken/hishtory/client/hctx"
|
"github.com/ddworken/hishtory/client/hctx"
|
||||||
@ -8,26 +9,24 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var force *bool
|
|
||||||
|
|
||||||
var GROUP_ID_MANAGEMENT string = "group_id_management"
|
var GROUP_ID_MANAGEMENT string = "group_id_management"
|
||||||
|
|
||||||
var redactCmd = &cobra.Command{
|
var redactCmd = &cobra.Command{
|
||||||
Use: "redact",
|
Use: "redact",
|
||||||
Aliases: []string{"delete"},
|
Aliases: []string{"delete"},
|
||||||
Short: "Query for matching commands and remove them from your shell history",
|
Short: "Query for matching commands and remove them from your shell history",
|
||||||
Long: "This removes history entries on the current machine and on all remote machines. Supports the same query format as 'hishtory query'.",
|
Long: "This removes history entries on the current machine and on all remote machines. Supports the same query format as 'hishtory query'.",
|
||||||
GroupID: GROUP_ID_MANAGEMENT,
|
GroupID: GROUP_ID_MANAGEMENT,
|
||||||
|
DisableFlagParsing: true,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
ctx := hctx.MakeContext()
|
ctx := hctx.MakeContext()
|
||||||
lib.CheckFatalError(lib.RetrieveAdditionalEntriesFromRemote(ctx))
|
lib.CheckFatalError(lib.RetrieveAdditionalEntriesFromRemote(ctx))
|
||||||
lib.CheckFatalError(lib.ProcessDeletionRequests(ctx))
|
lib.CheckFatalError(lib.ProcessDeletionRequests(ctx))
|
||||||
query := strings.Join(args, " ")
|
query := strings.Join(args, " ")
|
||||||
lib.CheckFatalError(lib.Redact(ctx, query, *force))
|
lib.CheckFatalError(lib.Redact(ctx, query, os.Getenv("HISHTORY_REDACT_FORCE") != ""))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(redactCmd)
|
rootCmd.AddCommand(redactCmd)
|
||||||
force = redactCmd.Flags().Bool("force", false, "Force redaction with no confirmation prompting")
|
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,5 @@ func main() {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Remaining things:
|
Remaining things:
|
||||||
* Support exclusions in searches
|
|
||||||
* Acutally migrate saveHistoryEntry to cobra
|
* Acutally migrate saveHistoryEntry to cobra
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user