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

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

View File

@ -11,6 +11,7 @@ import (
var configDeleteCmd = &cobra.Command{
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",
GroupID: GROUP_ID_CONFIG,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},

View File

@ -11,6 +11,7 @@ import (
var configSetCmd = &cobra.Command{
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

@ -9,6 +9,7 @@ import (
var enableCmd = &cobra.Command{
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))
@ -18,6 +19,7 @@ var enableCmd = &cobra.Command{
var disableCmd = &cobra.Command{
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

@ -10,6 +10,7 @@ import (
var importCmd = &cobra.Command{
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) {

View File

@ -16,6 +16,7 @@ var offline *bool
var initCmd = &cobra.Command{
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()

View File

@ -11,6 +11,7 @@ import (
var installCmd = &cobra.Command{
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())

View File

@ -21,9 +21,12 @@ 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",
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()
@ -34,7 +37,8 @@ var queryCmd = &cobra.Command{
var tqueryCmd = &cobra.Command{
Use: "tquery",
Short: "Interactively query your shell history",
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()
@ -44,7 +48,8 @@ var tqueryCmd = &cobra.Command{
var exportCmd = &cobra.Command{
Use: "export",
Short: "Export your shell history",
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()

View File

@ -10,10 +10,14 @@ import (
var force *bool
var GROUP_ID_MANAGEMENT string = "group_id_management"
var redactCmd = &cobra.Command{
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

@ -8,6 +8,7 @@ import (
var reuploadCmd = &cobra.Command{
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

@ -16,7 +16,8 @@ import (
var saveHistoryEntryCmd = &cobra.Command{
Use: "saveHistoryEntry",
// TODO: hide this from the help info?
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

@ -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
*/