Organize command groupings in hishtory help + unhide the install command (#278)

This commit is contained in:
David Dworken 2025-01-05 18:18:07 -05:00 committed by GitHub
parent 2ff52a8d66
commit 95f3a26a7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 25 additions and 17 deletions

View File

@ -15,8 +15,9 @@ import (
) )
var exportJsonCmd = &cobra.Command{ var exportJsonCmd = &cobra.Command{
Use: "export-json", Use: "export-json",
Short: "Export history entries formatted in JSON lines format (as accepted by hishtory import-json, and easily parsable by other tools)", Short: "Export history entries formatted in JSON lines format (as accepted by hishtory import-json, and easily parsable by other tools)",
GroupID: GROUP_ID_MANAGEMENT,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext() ctx := hctx.MakeContext()
err := exportToJson(ctx, os.Stdout) err := exportToJson(ctx, os.Stdout)

View File

@ -17,10 +17,11 @@ import (
) )
var importCmd = &cobra.Command{ var importCmd = &cobra.Command{
Use: "import", Use: "import",
Hidden: true, GroupID: GROUP_ID_MANAGEMENT,
Short: "Re-import history entries from your existing shell history", Hidden: true,
Long: "Note that you may also pipe commands to be imported in via stdin. For example `history | hishtory import`.", Short: "Re-import history entries from your existing shell history",
Long: "Note that you may also pipe commands to be imported in via stdin. For example `history | hishtory import`.",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext() ctx := hctx.MakeContext()
numImported, err := lib.ImportHistory(ctx, true, true) numImported, err := lib.ImportHistory(ctx, true, true)
@ -32,8 +33,9 @@ var importCmd = &cobra.Command{
} }
var importJsonCmd = &cobra.Command{ var importJsonCmd = &cobra.Command{
Use: "import-json", Use: "import-json",
Short: "Import history entries formatted in JSON lines format into hiSHtory", GroupID: GROUP_ID_MANAGEMENT,
Short: "Import history entries formatted in JSON lines format into hiSHtory",
Long: "Data is read from stdin. For example: `cat data.txt | hishtory import-json`.\n\nExample JSON format:\n\n```\n" + Long: "Data is read from stdin. For example: `cat data.txt | hishtory import-json`.\n\nExample JSON format:\n\n```\n" +
"{\"command\":\"echo foo\"}\n" + "{\"command\":\"echo foo\"}\n" +
"{\"command\":\"echo bar\", \"current_working_directory\": \"/tmp/\"}\n" + "{\"command\":\"echo bar\", \"current_working_directory\": \"/tmp/\"}\n" +

View File

@ -36,11 +36,13 @@ var (
currentlyInstalledVersion *string currentlyInstalledVersion *string
) )
var GROUP_ID_INSTALL string = "group_id_install"
var installCmd = &cobra.Command{ var installCmd = &cobra.Command{
Use: "install", Use: "install",
Hidden: true, Short: "Copy this binary to ~/.hishtory/ and configure your shell to use it for recording your shell history",
Short: "Copy this binary to ~/.hishtory/ and configure your shell to use it for recording your shell history", GroupID: GROUP_ID_INSTALL,
Args: cobra.MaximumNArgs(1), Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
secretKey := "" secretKey := ""
if len(args) > 0 { if len(args) > 0 {
@ -72,7 +74,7 @@ var installCmd = &cobra.Command{
var initCmd = &cobra.Command{ var initCmd = &cobra.Command{
Use: "init", Use: "init",
Short: "Re-initialize hiSHtory with a specified secret key", Short: "Re-initialize hiSHtory with a specified secret key",
GroupID: GROUP_ID_CONFIG, GroupID: GROUP_ID_INSTALL,
Args: cobra.MaximumNArgs(1), Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
db, err := hctx.OpenLocalSqliteDb() db, err := hctx.OpenLocalSqliteDb()
@ -107,8 +109,9 @@ var initCmd = &cobra.Command{
} }
var uninstallCmd = &cobra.Command{ var uninstallCmd = &cobra.Command{
Use: "uninstall", Use: "uninstall",
Short: "Completely uninstall hiSHtory and remove your shell history", Short: "Completely uninstall hiSHtory and remove your shell history",
GroupID: GROUP_ID_INSTALL,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext() ctx := hctx.MakeContext()
fmt.Printf("Are you sure you want to uninstall hiSHtory and delete all locally saved history data [y/N]") fmt.Printf("Are you sure you want to uninstall hiSHtory and delete all locally saved history data [y/N]")

View File

@ -30,5 +30,6 @@ func init() {
rootCmd.AddGroup(&cobra.Group{ID: GROUP_ID_QUERYING, Title: "History Searching"}) rootCmd.AddGroup(&cobra.Group{ID: GROUP_ID_QUERYING, Title: "History Searching"})
rootCmd.AddGroup(&cobra.Group{ID: GROUP_ID_MANAGEMENT, Title: "History Management"}) rootCmd.AddGroup(&cobra.Group{ID: GROUP_ID_MANAGEMENT, Title: "History Management"})
rootCmd.AddGroup(&cobra.Group{ID: GROUP_ID_CONFIG, Title: "Configuration"}) rootCmd.AddGroup(&cobra.Group{ID: GROUP_ID_CONFIG, Title: "Configuration"})
rootCmd.AddGroup(&cobra.Group{ID: GROUP_ID_INSTALL, Title: "Installation"})
rootCmd.Version = "v0." + lib.Version rootCmd.Version = "v0." + lib.Version
} }

View File

@ -22,8 +22,9 @@ import (
) )
var updateCmd = &cobra.Command{ var updateCmd = &cobra.Command{
Use: "update", Use: "update",
Short: "Securely update hishtory to the latest version", GroupID: GROUP_ID_INSTALL,
Short: "Securely update hishtory to the latest version",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
lib.CheckFatalError(update(hctx.MakeContext())) lib.CheckFatalError(update(hctx.MakeContext()))
}, },