package main import ( "context" "fmt" "os" "dehub.dev/src/dehub.git" "dehub.dev/src/dehub.git/cmd/dehub/dcmd" ) type cmdCtxKey int const ( cmdCtxKeyRepo cmdCtxKey = iota ) func ctxRepo(ctx context.Context) *dehub.Repo { repo, ok := ctx.Value(cmdCtxKeyRepo).(*dehub.Repo) if !ok { panic("repo not initialized on the command context") } return repo } func main() { cmd := dcmd.New() flag := cmd.FlagSet() bare := flag.Bool("bare", false, "If set then dehub will expect to be working with a bare repo") cmd.SubCmd("commit", "commits staged changes to the head of the current branch", cmdCommit) cmd.SubCmd("verify", "verifies one or more commits as having the proper credentials", cmdVerify) cmd.SubCmd("hook", "use dehub as a git hook", cmdHook) cmd.SubCmd("combine", "Combine multiple change and credential commits into a single commit", cmdCombine) cmd.Run(func() (context.Context, error) { repo, err := dehub.OpenRepo(".", dehub.OpenBare(*bare)) if err != nil { wd, _ := os.Getwd() return nil, fmt.Errorf("failed to OpenRepo at %q: %w", wd, err) } return context.WithValue(context.Background(), cmdCtxKeyRepo, repo), nil }) }