Better organize the cobra generated help page

This commit is contained in:
David Dworken 2022-11-14 20:18:22 -08:00
parent ecdd22dcdd
commit 27bbe97cb2
No known key found for this signature in database
15 changed files with 65 additions and 38 deletions

View File

@ -7,8 +7,9 @@ import (
)
var configAddCmd = &cobra.Command{
Use: "config-add",
Short: "Add a config option",
Use: "config-add",
Short: "Add a config option",
GroupID: GROUP_ID_CONFIG,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},

View File

@ -9,8 +9,9 @@ import (
)
var configDeleteCmd = &cobra.Command{
Use: "config-delete",
Short: "Delete a config option",
Use: "config-delete",
Short: "Delete a config option",
GroupID: GROUP_ID_CONFIG,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},

View File

@ -8,9 +8,12 @@ import (
"github.com/spf13/cobra"
)
var GROUP_ID_CONFIG string = "group_id_config"
var configGetCmd = &cobra.Command{
Use: "config-get",
Short: "Get the value of a config option",
Use: "config-get",
Short: "Get the value of a config option",
GroupID: GROUP_ID_CONFIG,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},

View File

@ -9,8 +9,9 @@ import (
)
var configSetCmd = &cobra.Command{
Use: "config-set",
Short: "Set the value of a config option",
Use: "config-set",
Short: "Set the value of a config option",
GroupID: GROUP_ID_CONFIG,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},

View File

@ -7,8 +7,9 @@ import (
)
var enableCmd = &cobra.Command{
Use: "enable",
Short: "Enable hiSHtory recording",
Use: "enable",
Short: "Enable hiSHtory recording",
GroupID: GROUP_ID_CONFIG,
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
lib.CheckFatalError(lib.Enable(ctx))
@ -16,8 +17,9 @@ var enableCmd = &cobra.Command{
}
var disableCmd = &cobra.Command{
Use: "disable",
Short: "Disable hiSHtory recording",
Use: "disable",
Short: "Disable hiSHtory recording",
GroupID: GROUP_ID_CONFIG,
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
lib.CheckFatalError(lib.Disable(ctx))

View File

@ -9,9 +9,10 @@ import (
)
var importCmd = &cobra.Command{
Use: "import",
Short: "Re-import history entries from your existing shell history",
Long: "Note that you must pipe commands to be imported in via stdin. For example `history | hishtory import`.",
Use: "import",
Hidden: true,
Short: "Re-import history entries from your existing shell history",
Long: "Note that you must pipe commands to be imported in via stdin. For example `history | hishtory import`.",
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
numImported, err := lib.ImportHistory(ctx, true, true)

View File

@ -14,9 +14,10 @@ import (
var offline *bool
var initCmd = &cobra.Command{
Use: "init",
Short: "Re-initialize hiSHtory with a specified secret key",
Args: cobra.MaximumNArgs(1),
Use: "init",
Short: "Re-initialize hiSHtory with a specified secret key",
GroupID: GROUP_ID_CONFIG,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
cmd.Flag("offline").Value.String()
db, err := hctx.OpenLocalSqliteDb()

View File

@ -10,8 +10,9 @@ import (
)
var installCmd = &cobra.Command{
Use: "install",
Short: "Copy this binary to ~/.hishtory/ and configure your shell to use it for recording your shell history",
Use: "install",
Hidden: true,
Short: "Copy this binary to ~/.hishtory/ and configure your shell to use it for recording your shell history",
Run: func(cmd *cobra.Command, args []string) {
lib.CheckFatalError(lib.Install())
if os.Getenv("HISHTORY_SKIP_INIT_IMPORT") == "" {

View File

@ -21,10 +21,13 @@ var EXAMPLE_QUERIES string = `Example queries:
'hishtory SUBCOMMAND before:2022-02-01' # Find shell commands run before 2022-02-01
`
var GROUP_ID_QUERYING string = "group_id:querying"
var queryCmd = &cobra.Command{
Use: "query",
Short: "Query your shell history",
Long: strings.ReplaceAll(EXAMPLE_QUERIES, "SUBCOMMAND", "query"),
Use: "query",
Short: "Query your shell history and display the results in an ASCII art table",
GroupID: GROUP_ID_QUERYING,
Long: strings.ReplaceAll(EXAMPLE_QUERIES, "SUBCOMMAND", "query"),
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
lib.CheckFatalError(lib.ProcessDeletionRequests(ctx))
@ -33,9 +36,10 @@ var queryCmd = &cobra.Command{
}
var tqueryCmd = &cobra.Command{
Use: "tquery",
Short: "Interactively query your shell history",
Long: strings.ReplaceAll(EXAMPLE_QUERIES, "SUBCOMMAND", "tquery"),
Use: "tquery",
Short: "Interactively query your shell history in a TUI interface",
GroupID: GROUP_ID_QUERYING,
Long: strings.ReplaceAll(EXAMPLE_QUERIES, "SUBCOMMAND", "tquery"),
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
lib.CheckFatalError(lib.TuiQuery(ctx, strings.Join(args, " ")))
@ -43,9 +47,10 @@ var tqueryCmd = &cobra.Command{
}
var exportCmd = &cobra.Command{
Use: "export",
Short: "Export your shell history",
Long: strings.ReplaceAll(EXAMPLE_QUERIES, "SUBCOMMAND", "export"),
Use: "export",
Short: "Export your shell history and display just the raw commands",
GroupID: GROUP_ID_QUERYING,
Long: strings.ReplaceAll(EXAMPLE_QUERIES, "SUBCOMMAND", "export"),
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
lib.CheckFatalError(lib.ProcessDeletionRequests(ctx))

View File

@ -10,10 +10,14 @@ import (
var force *bool
var GROUP_ID_MANAGEMENT string = "group_id_management"
var redactCmd = &cobra.Command{
Use: "redact",
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'.",
Use: "redact",
Aliases: []string{"delete"},
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'.",
GroupID: GROUP_ID_MANAGEMENT,
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
lib.CheckFatalError(lib.RetrieveAdditionalEntriesFromRemote(ctx))

View File

@ -7,8 +7,9 @@ import (
)
var reuploadCmd = &cobra.Command{
Use: "reupload",
Short: "[Debug Only] Reupload your entire hiSHtory to all other devices",
Use: "reupload",
Hidden: true,
Short: "[Debug Only] Reupload your entire hiSHtory to all other devices",
Run: func(cmd *cobra.Command, args []string) {
lib.CheckFatalError(lib.Reupload(hctx.MakeContext()))
},

View File

@ -24,4 +24,8 @@ func Execute() {
}
}
func init() {}
func init() {
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_CONFIG, Title: "Configuration"})
}

View File

@ -15,8 +15,9 @@ import (
)
var saveHistoryEntryCmd = &cobra.Command{
Use: "saveHistoryEntry",
// TODO: hide this from the help info?
Use: "saveHistoryEntry",
Hidden: true,
Short: "[Internal-only] The command used to save history entries",
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
lib.CheckFatalError(maybeUploadSkippedHistoryEntries(ctx))

View File

@ -13,7 +13,7 @@ var verbose *bool
var statusCmd = &cobra.Command{
Use: "status",
Short: "View status info including the secret key which is needed to sync shell history from another machine",
Short: "View status info including the secret key which is needed to sync shell history from another machine",
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
config := hctx.GetConf(ctx)

View File

@ -15,4 +15,5 @@ Remaining things:
* Support exclusions in searches
* Figure out how to hide certain things from the help doc
* Figure out how to reorder the docs
* Acutally migrate saveHistoryEntry to cobra
*/