mirror of
https://github.com/ddworken/hishtory.git
synced 2025-01-19 12:48:30 +01:00
Enable presaving by default rather than having it gated behind BetaMode
This commit is contained in:
parent
4f7cef19c9
commit
bed8998230
@ -2163,10 +2163,10 @@ func testPresaving(t *testing.T, tester shellTester) {
|
|||||||
userSecret := installHishtory(t, tester, "")
|
userSecret := installHishtory(t, tester, "")
|
||||||
manuallySubmitHistoryEntry(t, userSecret, testutils.MakeFakeHistoryEntry("table_sizing aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
|
manuallySubmitHistoryEntry(t, userSecret, testutils.MakeFakeHistoryEntry("table_sizing aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
|
||||||
|
|
||||||
// Enable beta-mode since presaving is behind that feature flag
|
// Enable the presaving feature
|
||||||
require.Equal(t, "false", strings.TrimSpace(tester.RunInteractiveShell(t, `hishtory config-get beta-mode`)))
|
require.Equal(t, "true", strings.TrimSpace(tester.RunInteractiveShell(t, `hishtory config-get presaving`)))
|
||||||
tester.RunInteractiveShell(t, `hishtory config-set beta-mode true`)
|
tester.RunInteractiveShell(t, `hishtory config-set presaving true`)
|
||||||
require.Equal(t, "true", strings.TrimSpace(tester.RunInteractiveShell(t, `hishtory config-get beta-mode`)))
|
require.Equal(t, "true", strings.TrimSpace(tester.RunInteractiveShell(t, `hishtory config-get presaving`)))
|
||||||
|
|
||||||
// Start a command that will take a long time to execute in the background, so
|
// Start a command that will take a long time to execute in the background, so
|
||||||
// we can check that it was recorded even though it never finished.
|
// we can check that it was recorded even though it never finished.
|
||||||
|
@ -61,6 +61,17 @@ var getEnableAiCompletion = &cobra.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var getPresavingCmd = &cobra.Command{
|
||||||
|
Use: "presaving",
|
||||||
|
Short: "Enable 'presaving' of shell entries that never finish running",
|
||||||
|
Long: "If enabled, there is a slight risk of duplicate history entries. If disabled, non-terminating history entries will not be recorded.",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
fmt.Println(config.EnablePresaving)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
var getBetaModeCmd = &cobra.Command{
|
var getBetaModeCmd = &cobra.Command{
|
||||||
Use: "beta-mode",
|
Use: "beta-mode",
|
||||||
Short: "Enable beta-mode to opt-in to unreleased features",
|
Short: "Enable beta-mode to opt-in to unreleased features",
|
||||||
@ -121,4 +132,5 @@ func init() {
|
|||||||
configGetCmd.AddCommand(getBetaModeCmd)
|
configGetCmd.AddCommand(getBetaModeCmd)
|
||||||
configGetCmd.AddCommand(getHighlightMatchesCmd)
|
configGetCmd.AddCommand(getHighlightMatchesCmd)
|
||||||
configGetCmd.AddCommand(getEnableAiCompletion)
|
configGetCmd.AddCommand(getEnableAiCompletion)
|
||||||
|
configGetCmd.AddCommand(getPresavingCmd)
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,23 @@ var setEnableAiCompletionCmd = &cobra.Command{
|
|||||||
lib.CheckFatalError(hctx.SetConfig(config))
|
lib.CheckFatalError(hctx.SetConfig(config))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
var setPresavingCmd = &cobra.Command{
|
||||||
|
Use: "presaving",
|
||||||
|
Short: "Enable 'presaving' of shell entries that never finish running",
|
||||||
|
Long: "If enabled, there is a slight risk of duplicate history entries. If disabled, non-terminating history entries will not be recorded.",
|
||||||
|
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
|
||||||
|
ValidArgs: []string{"true", "false"},
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
val := args[0]
|
||||||
|
if val != "true" && val != "false" {
|
||||||
|
log.Fatalf("Unexpected config value %s, must be one of: true, false", val)
|
||||||
|
}
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
config.EnablePresaving = (val == "true")
|
||||||
|
lib.CheckFatalError(hctx.SetConfig(config))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
var setHighlightMatchesCmd = &cobra.Command{
|
var setHighlightMatchesCmd = &cobra.Command{
|
||||||
Use: "highlight-matches",
|
Use: "highlight-matches",
|
||||||
@ -138,4 +155,5 @@ func init() {
|
|||||||
configSetCmd.AddCommand(setBetaModeCommand)
|
configSetCmd.AddCommand(setBetaModeCommand)
|
||||||
configSetCmd.AddCommand(setHighlightMatchesCmd)
|
configSetCmd.AddCommand(setHighlightMatchesCmd)
|
||||||
configSetCmd.AddCommand(setEnableAiCompletionCmd)
|
configSetCmd.AddCommand(setEnableAiCompletionCmd)
|
||||||
|
configSetCmd.AddCommand(setPresavingCmd)
|
||||||
}
|
}
|
||||||
|
@ -218,6 +218,10 @@ func handleUpgradedFeatures() error {
|
|||||||
// highlighting is not yet configured, so enable it
|
// highlighting is not yet configured, so enable it
|
||||||
config.HighlightMatches = true
|
config.HighlightMatches = true
|
||||||
}
|
}
|
||||||
|
if !strings.Contains(string(configContents), "enable_presaving") {
|
||||||
|
// Presaving is not yet configured, so enable it
|
||||||
|
config.HighlightMatches = true
|
||||||
|
}
|
||||||
if !strings.Contains(string(configContents), "ai_completion") {
|
if !strings.Contains(string(configContents), "ai_completion") {
|
||||||
// AI completion is not yet configured, disable it for upgrades since this is a new feature
|
// AI completion is not yet configured, disable it for upgrades since this is a new feature
|
||||||
config.AiCompletion = false
|
config.AiCompletion = false
|
||||||
@ -569,6 +573,7 @@ func setup(userSecret string, isOffline bool) error {
|
|||||||
// TODO: Set config.HighlightMatches = true here, so that we enable highlighting by default
|
// TODO: Set config.HighlightMatches = true here, so that we enable highlighting by default
|
||||||
config.AiCompletion = true
|
config.AiCompletion = true
|
||||||
config.IsOffline = isOffline
|
config.IsOffline = isOffline
|
||||||
|
config.EnablePresaving = true
|
||||||
err := hctx.SetConfig(&config)
|
err := hctx.SetConfig(&config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to persist config to disk: %w", err)
|
return fmt.Errorf("failed to persist config to disk: %w", err)
|
||||||
|
@ -142,7 +142,7 @@ func presaveHistoryEntry(ctx context.Context) {
|
|||||||
if !config.IsEnabled {
|
if !config.IsEnabled {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !config.BetaMode {
|
if !config.EnablePresaving {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ func saveHistoryEntry(ctx context.Context) {
|
|||||||
db := hctx.GetDb(ctx)
|
db := hctx.GetDb(ctx)
|
||||||
|
|
||||||
// Drop any entries from pre-saving since they're no longer needed
|
// Drop any entries from pre-saving since they're no longer needed
|
||||||
if config.BetaMode {
|
if config.EnablePresaving {
|
||||||
lib.CheckFatalError(deletePresavedEntries(ctx, entry, false))
|
lib.CheckFatalError(deletePresavedEntries(ctx, entry, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,7 +220,7 @@ func saveHistoryEntry(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.BetaMode {
|
if config.EnablePresaving {
|
||||||
db.Commit()
|
db.Commit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,6 +199,8 @@ type ClientConfig struct {
|
|||||||
HighlightMatches bool `json:"highlight_matches"`
|
HighlightMatches bool `json:"highlight_matches"`
|
||||||
// Whether to enable AI completion
|
// Whether to enable AI completion
|
||||||
AiCompletion bool `json:"ai_completion"`
|
AiCompletion bool `json:"ai_completion"`
|
||||||
|
// Whether to enable presaving
|
||||||
|
EnablePresaving bool `json:"enable_presaving"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CustomColumnDefinition struct {
|
type CustomColumnDefinition struct {
|
||||||
|
@ -840,7 +840,8 @@ func retryingSearch(ctx context.Context, db *gorm.DB, query string, limit int, c
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if hctx.GetConf(ctx).BetaMode {
|
if hctx.GetConf(ctx).EnablePresaving {
|
||||||
|
// Sort by StartTime when presaving is enabled, since presaved entries may not have an end time
|
||||||
tx = tx.Order("start_time DESC")
|
tx = tx.Order("start_time DESC")
|
||||||
} else {
|
} else {
|
||||||
tx = tx.Order("end_time DESC")
|
tx = tx.Order("end_time DESC")
|
||||||
|
Loading…
Reference in New Issue
Block a user