mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 16:27:33 -10:00
devvm --help lists the commands in groups: Your VM, Change your VM, Images, Disk space and This machine, with help under Cobra's Additional Commands. A group whose commands don't exist yet, such as Links between VMs, stays out of the help. Each command's Long is one to three sentences, and the rules it held are on the command's docs page. Every visible command has an Example, with the most common invocations first, each with a comment. Flag descriptions are shorter. Each help ends with the address of the command's docs page, and the root's also ends with the issue tracker. - internal/cli/help.go: commandGroups, addGroups, addDocs (Cobra's usage template with Docs and Issues sections), examples - internal/msg/docs.go: commandDocs, CommandDoc, CommandDocURL, IssuesURL; TestDocLinks checks commandDocs (user pages only) - docgen: each reference page has a Docs section before See also - docs: commands.md in the help's groups, with new sections on restarting and stopping and on deleting a VM; install.md has doctor's engine, feature values, Docker and CA notes; Contributing describes a command's help - tests: TestExamples, TestHelpGroupsAndDocs, TestAddGroups, TestWithDocs, TestCheckCommandDocs Co-Authored-By: Claude Opus 5.5 <[email protected]>
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
package cli
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/w3cj/devvm/internal/gitprotect"
|
|
"github.com/w3cj/devvm/internal/msg"
|
|
"github.com/w3cj/devvm/internal/ui"
|
|
"github.com/w3cj/devvm/internal/vm"
|
|
)
|
|
|
|
// newGitProtectCmd is devvm git-protect [on|strict|off].
|
|
func newGitProtectCmd(u *ui.UI) *cobra.Command {
|
|
var asJSON bool
|
|
cmd := &cobra.Command{
|
|
Use: "git-protect [on|strict|off]",
|
|
Short: "Show or change .git protection for this folder's VM",
|
|
Long: "Show this folder's VM's .git protection, which locks the git hooks and config that run code on this machine, " +
|
|
"as on, strict, off, or clone for a --clone VM. " +
|
|
"devvm git-protect on, strict or off changes it while the VM is stopped.",
|
|
Example: examples(
|
|
"devvm git-protect", "show the VM's .git protection",
|
|
"devvm stop && devvm git-protect off", "unlock .git, which needs the VM stopped",
|
|
"devvm git-protect on", "lock .git again as it is now",
|
|
),
|
|
Args: showsOnly(maxArgs(1)),
|
|
ValidArgs: gitprotect.Modes,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
var mode string
|
|
withEnv(u, func(env *vm.Env) error {
|
|
s := vm.Settings{Env: env}
|
|
if len(args) == 1 {
|
|
return s.SetGitProtect(cmd.Context(), args[0])
|
|
}
|
|
var err error
|
|
mode, err = s.GitProtect(cmd.Context())
|
|
return err
|
|
}, msg.GitProtectFailed)
|
|
if len(args) == 1 {
|
|
return nil
|
|
}
|
|
return printValue(u, asJSON, "mode", mode)
|
|
},
|
|
}
|
|
jsonFlag(cmd, &asJSON)
|
|
return cmd
|
|
}
|