Skip to content

Consider changing cmd/ directory as cobra command recommendation #641

@integrii

Description

@integrii

Hello @spf13 and thank you for your many great contributions. I contributed to Hugo some time ago and use it for several sites!

The typical go pattern is to use the cmd directory like an index of all buildable binaries in a project. Cobra directly conflicts with this by recommending that the cmd directory is used to hold small packages which each contain cobra command packages.

Please consider recommending a more compatible file structure, such as this one that nests cobra commands with their relevant binaries:

project/
    Dockerfile
    kubernetes.yaml
    README.md
    cmd/
        binaryNameA/
            main.go
            cobraCommandA/
                cobraCommandA.go
            cobraCommandB/
                cobraCommandB.go
        binaryNameB/
            main.go
            otherStuff.go
    pkg/
        packageName/
            packageName.go

Or perhaps this layout, which organizes the cobra command packages as packages:

project/
    Dockerfile
    kubernetes.yaml
    README.md
    cmd/
        binaryNameA/
            main.go
        binaryNameB/
            main.go
            otherStuff.go
    pkg/
        packageName/
            packageName.go
        cobraCommandA/
            cobraCommandA.go
        cobraCommandB/
            cobraCommandB.go

The goal here is to enable the typical cmd/ directory behavior - rather than trying to make cobra users decide which layout to use.

Thanks again!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions