diff --git a/.gitignore b/.gitignore index cdf3db6..bff1fd3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ dh-make-golang +dh-make-golang.1 _build/ *~ *.sw[op] diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md new file mode 100644 index 0000000..355a494 --- /dev/null +++ b/DEVELOPMENT.md @@ -0,0 +1,184 @@ +# Development Guide for dh-make-golang + +This document provides comprehensive information about the development structure, contribution guidelines, and file organization of the dh-make-golang project. + +## Project Overview + +dh-make-golang is a tool that automates the creation of Debian packaging for Go packages. It follows the [pkg-go packaging guidelines](https://go-team.pages.debian.net/packaging.html) and is designed to simplify the process of creating Debian packages for Go libraries and programs. + +## Repository Structure + +The project is organized as follows: + +``` +dh-make-golang/ +├── cmd/ # Command implementation files +│ ├── check_depends.go # Check dependencies command +│ ├── clone.go # Clone command +│ ├── completion.go # Shell completion +│ ├── make.go # Main make command +│ ├── root.go # Root command definition +│ └── ... +├── .github/ # GitHub-specific files +│ └── workflows/ # CI/CD workflow definitions +├── main.go # Application entry point +├── make.go # Package creation logic +├── version.go # Version information +├── go.mod # Go module definition +├── go.sum # Go module checksums +└── ... # Other utility files +``` + +### Key Components + +- **cmd/**: Contains the implementation of all CLI commands using the Cobra framework +- **main.go**: Entry point that initializes the application and GitHub client +- **make.go**: Core functionality for creating Debian packages +- **version.go**: Version information and management +- **description.go**: Package description handling +- **clone.go**: Repository cloning functionality +- **estimate.go**: Dependency estimation functionality + +## Build and Run + +### Build from source + +```bash +# Clone the repository +git clone https://github.com/Debian/dh-make-golang.git +cd dh-make-golang + +# Build the binary +go build -o dh-make-golang + +# Install (optional) +sudo install -m755 dh-make-golang /usr/local/bin/ +``` + +### Run + +```bash +# Basic usage +dh-make-golang make github.com/example/package + +# Get help +dh-make-golang --help + +# Get help for a specific command +dh-make-golang make --help +``` + +## Development Workflow + +### Setting up the Development Environment + +1. Ensure you have Go 1.21+ installed +2. Clone the repository +3. Install development dependencies: + ```bash + go get -v ./... + ``` + +### Using the Makefile + +The project includes a Makefile to simplify common development tasks. To see all available commands: + +```bash +make help +``` + +#### Available Make Commands + +| Command | Description | Example | +|---------|-------------|---------| +| `make build` | Builds the binary | `make build` | +| `make test` | Runs all tests | `make test` | +| `make lint` | Runs formatting and linting checks | `make lint` | +| `make fmt` | Formats code using gofmt | `make fmt` | +| `make vet` | Runs go vet for static analysis | `make vet` | +| `make clean` | Removes build artifacts | `make clean` | +| `make install` | Installs binary to /usr/local/bin | `make install` | +| `make man` | Generates man page from markdown | `make man` | + +### Testing + +The project uses Go's standard testing framework. Run tests with: + +```bash +make test +``` + +Or directly with Go: + +```bash +go test -v ./... +``` + +### Code Style + +The project follows Go standard code style. Before submitting changes: + +1. Format your code: + ```bash + make fmt + ``` +2. Run linting: + ```bash + make lint + ``` + +### Environment Variables + +The following environment variables can be used during development: + +- `GITHUB_USERNAME`: GitHub username for API authentication +- `GITHUB_PASSWORD`: GitHub password or token for API authentication +- `GITHUB_OTP`: One-time password for GitHub 2FA (if enabled) + +## Continuous Integration + +The project uses GitHub Actions for CI/CD. The workflow: + +1. Runs on multiple Go versions (1.21, 1.22) +2. Checks code formatting +3. Builds the project +4. Runs tests +5. Performs static analysis +6. Tests package creation with a real-world example + +## Making Contributions + +### Pull Request Process + +1. Fork the repository +2. Create a feature branch +3. Make your changes +4. Run tests and ensure they pass +5. Submit a pull request + +### Commit Guidelines + +- Use clear, descriptive commit messages +- Reference issue numbers when applicable +- Keep commits focused on single changes + +### Documentation + +When adding new features or modifying existing ones: + +1. Update relevant documentation +2. Add comments to complex code sections +3. Update the man page if necessary (generated from dh-make-golang.md) + +## Release Process + +1. Update version information in version.go +2. Update changelog +3. Create a tag for the new version +4. Build and test the release +5. Push the tag to trigger release workflows + +## Additional Resources + +- [pkg-go packaging guidelines](https://go-team.pages.debian.net/packaging.html) +- [Debian Salsa](https://wiki.debian.org/Salsa) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..603354b --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +.PHONY: build test lint fmt vet clean install man help + +BINARY_NAME=dh-make-golang +GO=go +GOFMT=gofmt +PANDOC=pandoc + +help: + @echo "Available targets:" + @echo " build - Build the binary" + @echo " test - Run tests" + @echo " lint - Run linting checks" + @echo " fmt - Format code" + @echo " vet - Run go vet" + @echo " clean - Remove build artifacts" + @echo " install - Install binary to /usr/local/bin" + @echo " man - Generate man page" + +build: + $(GO) build -o $(BINARY_NAME) + +test: + $(GO) test -v ./... + +lint: fmt vet + +fmt: + $(GOFMT) -w -s . + +vet: + $(GO) vet ./... + +clean: + rm -f $(BINARY_NAME) + rm -f $(BINARY_NAME).1 + +install: build + install -m755 $(BINARY_NAME) /usr/local/bin/ + +man: + $(PANDOC) -f markdown -t man -s dh-make-golang.md -o $(BINARY_NAME).1 diff --git a/cmd/check_depends.go b/cmd/check_depends.go new file mode 100644 index 0000000..c0cb600 --- /dev/null +++ b/cmd/check_depends.go @@ -0,0 +1,15 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +// checkDependsCmd represents the check-depends command +var checkDependsCmd = &cobra.Command{ + Use: "check-depends", + Short: "Compare go.mod and d/control to check for changes", + Long: `Compare go.mod and d/control to check for changes in dependencies.`, + Run: func(cmd *cobra.Command, args []string) { + execCheckDepends(args) + }, +} diff --git a/cmd/clone.go b/cmd/clone.go new file mode 100644 index 0000000..13ad654 --- /dev/null +++ b/cmd/clone.go @@ -0,0 +1,17 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +// cloneCmd represents the clone command +var cloneCmd = &cobra.Command{ + Use: "clone ", + Short: "Clone a Go package from Salsa", + Long: `Clone a Go package from Salsa and download the appropriate tarball.`, + Example: "dh-make-golang clone golang-github-mmcdole-goxpp", + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + execClone(args) + }, +} diff --git a/cmd/completion.go b/cmd/completion.go new file mode 100644 index 0000000..2da4c14 --- /dev/null +++ b/cmd/completion.go @@ -0,0 +1,43 @@ +package cmd + +import ( + "os" + + "github.com/spf13/cobra" +) + +// completionCmd represents the completion command +var completionCmd = &cobra.Command{ + Use: "completion [bash|zsh|fish]", + Short: "Generate shell completion scripts", + Long: `Generate shell completion scripts for dh-make-golang. +To load completions: + +Bash: + $ source <(dh-make-golang completion bash) + +Zsh: + # If shell completion is not already enabled in your environment, + # you will need to enable it. You can execute the following once: + $ echo "autoload -U compinit; compinit" >> ~/.zshrc + + # To load completions for each session, execute once: + $ dh-make-golang completion zsh > "${fpath[1]}/_dh-make-golang" + +Fish: + $ dh-make-golang completion fish | source +`, + DisableFlagsInUseLine: true, + ValidArgs: []string{"bash", "zsh", "fish"}, + Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), + Run: func(cmd *cobra.Command, args []string) { + switch args[0] { + case "bash": + cmd.Root().GenBashCompletion(os.Stdout) + case "zsh": + cmd.Root().GenZshCompletion(os.Stdout) + case "fish": + cmd.Root().GenFishCompletion(os.Stdout, true) + } + }, +} diff --git a/cmd/create_salsa_project.go b/cmd/create_salsa_project.go new file mode 100644 index 0000000..5388e6b --- /dev/null +++ b/cmd/create_salsa_project.go @@ -0,0 +1,17 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +// createSalsaProjectCmd represents the create-salsa-project command +var createSalsaProjectCmd = &cobra.Command{ + Use: "create-salsa-project ", + Short: "Create a project for hosting Debian packaging", + Long: `Create a project for hosting Debian packaging on Salsa.`, + Example: "dh-make-golang create-salsa-project golang-github-mattn-go-sqlite3", + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + execCreateSalsaProject(args) + }, +} diff --git a/cmd/estimate.go b/cmd/estimate.go new file mode 100644 index 0000000..cf1c446 --- /dev/null +++ b/cmd/estimate.go @@ -0,0 +1,31 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var ( + // Estimate command flags + estimateGitRevision string +) + +// estimateCmd represents the estimate command +var estimateCmd = &cobra.Command{ + Use: "estimate ", + Short: "Estimate the amount of work for a package", + Long: `Estimates the work necessary to bring into Debian +by printing all currently unpacked repositories.`, + Example: "dh-make-golang estimate github.com/Debian/dh-make-golang", + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + execEstimate(args) + }, +} + +func init() { + // Add flags to the estimate command + estimateCmd.Flags().StringVar(&estimateGitRevision, "git-revision", "", + "git revision (see gitrevisions(7)) of the specified Go package\n"+ + "to estimate, defaulting to the default behavior of go get.\n"+ + "Useful in case you do not want to estimate the latest version.") +} diff --git a/cmd/exports.go b/cmd/exports.go new file mode 100644 index 0000000..ab738b0 --- /dev/null +++ b/cmd/exports.go @@ -0,0 +1,37 @@ +package cmd + +// This file contains exported functions from the main package +// that are used by the cobra commands. + +// These functions should be imported from the main package +// and properly implemented here. + +// Placeholder declarations for the exec* functions +// These should be replaced with the actual implementations +// from the main package. + +var ( + execSearch func(args []string) + execCreateSalsaProject func(args []string) + execEstimate func(args []string) + execMake func(args []string, usage func()) + execClone func(args []string) + execCheckDepends func(args []string) +) + +// SetExecFunctions sets the exec functions from the main package +func SetExecFunctions( + search func(args []string), + createSalsaProject func(args []string), + estimate func(args []string), + make func(args []string, usage func()), + clone func(args []string), + checkDepends func(args []string), +) { + execSearch = search + execCreateSalsaProject = createSalsaProject + execEstimate = estimate + execMake = make + execClone = clone + execCheckDepends = checkDepends +} diff --git a/cmd/make.go b/cmd/make.go new file mode 100644 index 0000000..298e831 --- /dev/null +++ b/cmd/make.go @@ -0,0 +1,80 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var ( + // Make command flags + gitRevision string + allowUnknownHoster bool + dep14 bool + pristineTar bool + forcePrerelease bool + pkgTypeString string + customProgPkgName string + includeUpstreamHistory bool + wrapAndSortFlag string +) + +// makeCmd represents the make command +var makeCmd = &cobra.Command{ + Use: "make [flags] ", + Short: "Create a Debian package", + Long: `"dh-make-golang make" downloads the specified Go package from the Internet, +and creates new files and directories in the current working directory.`, + Example: "dh-make-golang make golang.org/x/oauth2", + Run: func(cmd *cobra.Command, args []string) { + execMake(args, nil) + }, +} + +func init() { + // Add flags to the make command + makeCmd.Flags().StringVar(&gitRevision, "git-revision", "", + "git revision (see gitrevisions(7)) of the specified Go package\n"+ + "to check out, defaulting to the default behavior of git clone.\n"+ + "Useful in case you do not want to package e.g. current HEAD.") + + makeCmd.Flags().BoolVar(&allowUnknownHoster, "allow-unknown-hoster", false, + "The pkg-go naming conventions use a canonical identifier for\n"+ + "the hostname (see https://go-team.pages.debian.net/packaging.html),\n"+ + "and the mapping is hardcoded into dh-make-golang.\n"+ + "In case you want to package a Go package living on an unknown hoster,\n"+ + "you may set this flag to true and double-check that the resulting\n"+ + "package name is sane. Contact pkg-go if unsure.") + + makeCmd.Flags().BoolVar(&dep14, "dep14", true, + "Follow DEP-14 branch naming and use debian/sid (instead of master)\n"+ + "as the default debian-branch.") + + makeCmd.Flags().BoolVar(&pristineTar, "pristine-tar", false, + "Keep using a pristine-tar branch as in the old workflow.\n"+ + "Discouraged, see \"pristine-tar considered harmful\"\n"+ + "https://michael.stapelberg.ch/posts/2018-01-28-pristine-tar/\n"+ + "and the \"Drop pristine-tar branches\" section at\n"+ + "https://go-team.pages.debian.net/workflow-changes.html") + + makeCmd.Flags().BoolVar(&forcePrerelease, "force-prerelease", false, + "Package @master or @tip instead of the latest tagged version") + + makeCmd.Flags().StringVar(&pkgTypeString, "type", "", + "Set package type, one of:\n"+ + " * \"library\" (aliases: \"lib\", \"l\", \"dev\")\n"+ + " * \"program\" (aliases: \"prog\", \"p\")\n"+ + " * \"library+program\" (aliases: \"lib+prog\", \"l+p\", \"both\")\n"+ + " * \"program+library\" (aliases: \"prog+lib\", \"p+l\", \"combined\")") + + makeCmd.Flags().StringVar(&customProgPkgName, "program-package-name", "", + "Override the program package name, and the source package name too\n"+ + "when appropriate, e.g. to name github.com/cli/cli as \"gh\"") + + makeCmd.Flags().BoolVar(&includeUpstreamHistory, "upstream-git-history", true, + "Include upstream git history (Debian pkg-go team new workflow).\n"+ + "New in dh-make-golang 0.3.0, currently experimental.") + + makeCmd.Flags().StringVar(&wrapAndSortFlag, "wrap-and-sort", "at", + "Set how the various multi-line fields in debian/control are formatted.\n"+ + "Valid values are \"a\", \"at\" and \"ast\", see wrap-and-sort(1) man page\n"+ + "for more information.") +} diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..de36678 --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,41 @@ +package cmd + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" +) + +const program = "dh-make-golang" + +// rootCmd represents the base command when called without any subcommands +var rootCmd = &cobra.Command{ + Use: program, + Short: "A tool that converts Go packages into Debian package source", + Long: `dh-make-golang is a tool that converts Go packages into Debian package source. +For backwards compatibility, when no command is specified, the make command is executed.`, + // When no arguments are provided, show help instead of running make command + Run: nil, + Version: buildVersionString(), +} + +// Execute adds all child commands to the root command and sets flags appropriately. +// This is called by main.main(). It only needs to happen once to the rootCmd. +func Execute() { + if err := rootCmd.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } +} + +func init() { + // Add commands + rootCmd.AddCommand(searchCmd) + rootCmd.AddCommand(createSalsaProjectCmd) + rootCmd.AddCommand(estimateCmd) + rootCmd.AddCommand(makeCmd) + rootCmd.AddCommand(cloneCmd) + rootCmd.AddCommand(checkDependsCmd) + rootCmd.AddCommand(completionCmd) +} diff --git a/cmd/search.go b/cmd/search.go new file mode 100644 index 0000000..22f4664 --- /dev/null +++ b/cmd/search.go @@ -0,0 +1,17 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +// searchCmd represents the search command +var searchCmd = &cobra.Command{ + Use: "search [flags] ", + Short: "Search Debian for already-existing packages", + Long: `Search Debian for already-existing packages using Go's default regexp syntax.`, + Example: "dh-make-golang search 'debi.*'", + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + execSearch(args) + }, +} diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..2e549bd --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,31 @@ +package cmd + +import ( + "fmt" + "runtime" +) + +// Version represents the dh-make-golang build version. +type Version struct { + major int + minor int + patch int + preRelease string +} + +var currentVersion = Version{ + major: 0, + minor: 8, + patch: 0, + preRelease: "", +} + +func (v Version) String() string { + return fmt.Sprintf("%d.%d.%d%s", v.major, v.minor, v.patch, v.preRelease) +} + +func buildVersionString() string { + version := "v" + currentVersion.String() + osArch := runtime.GOOS + "/" + runtime.GOARCH + return fmt.Sprintf("%s %s %s", program, version, osArch) +} diff --git a/dh-make-golang.md b/dh-make-golang.md index 351888e..c28fa86 100644 --- a/dh-make-golang.md +++ b/dh-make-golang.md @@ -1,4 +1,4 @@ -% DH-MAKE-GOLANG(1) 2018-09-15 +% DH-MAKE-GOLANG(1) 2025-06-14 # NAME @@ -12,37 +12,101 @@ dh-make-golang - automatically creates Debian packaging for Go packages **dh-make-golang** is a tool to automatically create Debian packaging for Go packages. Its goal is to automate away as much of the work as possible when -creating a Debian package for a Go library package. +creating a Debian package for a Go library package or Go program. For backwards compatibility, when no command is specified, the **make** command is executed. To learn more about a command, run -"dh-make-golang <*command*> -help", for example "dh-make-golang make -help". +"dh-make-golang <*command*> --help", for example "dh-make-golang make --help". # COMMANDS -**make** *go-package-importpath* +**make** [*flags*] *go-package-importpath* : Create a Debian package. **dh-make-golang** will create new files and directories in the current working directory. It will connect to the internet to download the specified Go package. + Common flags: + + **--git-revision**=*revision* + : Specify a git revision to check out. + + **--type**=*type* + : Set package type (library, program, library+program, program+library). + + **--program-package-name**=*name* + : Override the program package name. + + **--force-prerelease** + : Package @master or @tip instead of the latest tagged version. + + **--pristine-tar** + : Keep using a pristine-tar branch as in the old workflow. + **search** *pattern* : Search Debian for already-existing packages. Uses Go's default regexp syntax (https://golang.org/pkg/regexp/syntax/). -**estimate** *go-package-importpath* +**estimate** [*flags*] *go-package-importpath* : Estimates the work necessary to bring *go-package-importpath* into Debian by printing all currently unpacked repositories. + + Flags: + + **--git-revision**=*revision* + : Specify a git revision to estimate. **create-salsa-project** *project-name* -: Create a project for hosting Debian packaging. +: Create a project for hosting Debian packaging on Salsa. + +**clone** *package-name* +: Clone a Go package from Salsa and download the appropriate tarball. + +**check-depends** +: Compare go.mod and d/control to check for changes in dependencies. + +**completion** [*bash*|*zsh*|*fish*] +: Generate shell completion scripts for dh-make-golang. + +# EXAMPLES + +Create a Debian package for a Go library: + +``` +dh-make-golang make --type library golang.org/x/oauth2 +``` + +Create a Debian package for a Go program: + +``` +dh-make-golang make --type program github.com/cli/cli --program-package-name gh +``` + +Search for existing packages: + +``` +dh-make-golang search 'github.com/mattn' +``` + +Clone an existing package: + +``` +dh-make-golang clone golang-github-mmcdole-goxpp +``` + +Generate shell completion: + +``` +dh-make-golang completion bash > /etc/bash_completion.d/dh-make-golang +``` -# OPTIONS +# ENVIRONMENT VARIABLES -Run **dh-make-golang** -help for more details. +**GITHUB_USERNAME**, **GITHUB_PASSWORD**, **GITHUB_OTP** +: GitHub credentials for API authentication. Used when accessing GitHub repositories. # SEE ALSO -**dh**(1), **dh_golang**(1), **Debian::Debhelper::Buildsystem::golang**(3pm) +**dh**(1), **dh_golang**(1), **Debian::Debhelper::Buildsystem::golang**(3pm), **wrap-and-sort**(1) # AUTHOR diff --git a/go.mod b/go.mod index 87b4e4b..53f3a82 100644 --- a/go.mod +++ b/go.mod @@ -7,10 +7,10 @@ require ( github.com/google/go-github/v60 v60.0.0 github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 github.com/mattn/go-isatty v0.0.20 + github.com/spf13/cobra v1.8.0 golang.org/x/mod v0.19.0 golang.org/x/net v0.27.0 golang.org/x/sync v0.7.0 - golang.org/x/tools v0.23.0 golang.org/x/tools/go/vcs v0.1.0-deprecated pault.ag/go/debian v0.16.0 ) @@ -24,12 +24,14 @@ require ( github.com/dlclark/regexp2 v1.11.0 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/gorilla/css v1.0.1 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/microcosm-cc/bluemonday v1.0.27 // indirect github.com/muesli/reflow v0.3.0 // indirect github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a // indirect github.com/rivo/uniseg v0.4.7 // indirect + github.com/spf13/pflag v1.0.5 // indirect github.com/yuin/goldmark v1.7.4 // indirect github.com/yuin/goldmark-emoji v1.0.3 // indirect golang.org/x/crypto v0.25.0 // indirect diff --git a/go.sum b/go.sum index 20b0f7b..442cb13 100644 --- a/go.sum +++ b/go.sum @@ -18,6 +18,7 @@ github.com/charmbracelet/x/ansi v0.1.4 h1:IEU3D6+dWwPSgZ6HBH+v6oUuZ/nVawMiWj5831 github.com/charmbracelet/x/ansi v0.1.4/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= github.com/charmbracelet/x/exp/golden v0.0.0-20240715153702-9ba8adf781c4 h1:6KzMkQeAF56rggw2NZu1L+TH7j9+DM1/2Kmh7KUxg1I= github.com/charmbracelet/x/exp/golden v0.0.0-20240715153702-9ba8adf781c4/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= +github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI= github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -33,6 +34,8 @@ github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 h1:+ngKgrYPPJr github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= @@ -50,6 +53,11 @@ github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= +github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= github.com/yuin/goldmark v1.7.4 h1:BDXOHExt+A7gwPCJgPIIq7ENvceR7we7rOS9TNoLZeg= github.com/yuin/goldmark v1.7.4/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= @@ -57,14 +65,10 @@ github.com/yuin/goldmark-emoji v1.0.3 h1:aLRkLHOuBR2czCY4R8olwMjID+tENfhyFDMCRhb github.com/yuin/goldmark-emoji v1.0.3/go.mod h1:tTkZEbwu5wkPmgTcitqddVxY9osFZiavD+r4AzQrh1U= golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= -golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8= -golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -72,13 +76,11 @@ golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= -golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= -golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= -golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg= -golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI= golang.org/x/tools/go/vcs v0.1.0-deprecated h1:cOIJqWBl99H1dH5LWizPa+0ImeeJq3t3cJjaeOWUAL4= golang.org/x/tools/go/vcs v0.1.0-deprecated/go.mod h1:zUrvATBAvEI9535oC0yWYsLsHIV4Z7g63sNPVMtuBy8= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= pault.ag/go/debian v0.16.0 h1:fivXn/IO9rn2nzTGndflDhOkNU703Axs/StWihOeU2g= pault.ag/go/debian v0.16.0/go.mod h1:JFl0XWRCv9hWBrB5MDDZjA5GSEs1X3zcFK/9kCNIUmE= pault.ag/go/topsort v0.1.1 h1:L0QnhUly6LmTv0e3DEzbN2q6/FGgAcQvaEw65S53Bg4= diff --git a/main.go b/main.go index 4dfed1f..e188d49 100644 --- a/main.go +++ b/main.go @@ -1,41 +1,18 @@ package main import ( - "fmt" - "os" - + "github.com/Debian/dh-make-golang/cmd" "github.com/google/go-github/v60/github" "github.com/gregjones/httpcache" + "os" ) -const program = "dh-make-golang" - var ( gitHub *github.Client ) -func usage() { - fmt.Fprintf(os.Stderr, "%s\n", buildVersionString()) - fmt.Fprintf(os.Stderr, "\n") - fmt.Fprintf(os.Stderr, "%s is a tool that converts Go packages into Debian package source.\n", program) - fmt.Fprintf(os.Stderr, "\n") - fmt.Fprintf(os.Stderr, "Usage:\n\t%s [globalflags] [flags] \n", program) - fmt.Fprintf(os.Stderr, "\n") - fmt.Fprintf(os.Stderr, "%s commands:\n", program) - fmt.Fprintf(os.Stderr, "\tmake\t\t\tcreate a Debian package\n") - fmt.Fprintf(os.Stderr, "\tsearch\t\t\tsearch Debian for already-existing packages\n") - fmt.Fprintf(os.Stderr, "\testimate\t\testimate the amount of work for a package\n") - fmt.Fprintf(os.Stderr, "\tcreate-salsa-project\tcreate a project for hosting Debian packaging\n") - fmt.Fprintf(os.Stderr, "\tclone\t\t\tclone a Go package from Salsa\n") - fmt.Fprintf(os.Stderr, "\tcheck-depends\t\tcompare go.mod and d/control to check for changes\n") - fmt.Fprintf(os.Stderr, "\n") - fmt.Fprintf(os.Stderr, "For backwards compatibility, when no command is specified,\nthe make command is executed.\n") - fmt.Fprintf(os.Stderr, "\n") - fmt.Fprintf(os.Stderr, "To learn more about a command, run \"%s -help\",\ne.g. \"%s make -help\"\n", program, program) - fmt.Fprintf(os.Stderr, "\n") -} - -func main() { +func init() { + // Initialize GitHub client transport := github.BasicAuthTransport{ Username: os.Getenv("GITHUB_USERNAME"), Password: os.Getenv("GITHUB_PASSWORD"), @@ -44,32 +21,41 @@ func main() { } gitHub = github.NewClient(transport.Client()) - // Retrieve args and Shift binary name off argument list. - args := os.Args[1:] + // Set the exec functions for the cmd package + cmd.SetExecFunctions( + execSearch, + execCreateSalsaProject, + execEstimate, + execMake, + execClone, + execCheckDepends, + ) +} + +func main() { + // For backward compatibility, add aliases for flags with underscores + os.Args = updateFlagNames(os.Args) + cmd.Execute() +} - // Retrieve command name as first argument. - cmd := "" - if len(args) > 0 { - cmd = args[0] +// updateFlagNames replaces underscore flags with hyphen flags for backward compatibility +func updateFlagNames(args []string) []string { + flagsToUpdate := map[string]string{ + "git_revision": "git-revision", + "allow_unknown_hoster": "allow-unknown-hoster", + "force_prerelease": "force-prerelease", + "program_package_name": "program-package-name", + "upstream_git_history": "upstream-git-history", } - switch cmd { - case "help": - usage() - case "search": - execSearch(args[1:]) - case "create-salsa-project": - execCreateSalsaProject(args[1:]) - case "estimate": - execEstimate(args[1:]) - case "make": - execMake(args[1:], nil) - case "clone": - execClone(args[1:]) - case "check-depends": - execCheckDepends(args[1:]) - default: - // redirect -help to the global usage - execMake(args, usage) + for i, arg := range args { + for oldFlag, newFlag := range flagsToUpdate { + if arg == "--"+oldFlag || arg == "-"+oldFlag { + args[i] = "--" + newFlag + break + } + } } + + return args } diff --git a/version_current.go b/version_current.go index 2597a1b..d92c591 100644 --- a/version_current.go +++ b/version_current.go @@ -5,6 +5,9 @@ import ( "runtime" ) +// Program name +const program = "dh-make-golang" + // Version represents the dh-make-golang build version. type Version struct { major int