Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions check_depends.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"flag"
"fmt"
"log"
"os"
Expand All @@ -19,6 +20,31 @@ type dependency struct {
}

func execCheckDepends(args []string) {
fs := flag.NewFlagSet("check-depends", flag.ExitOnError)
fs.Usage = func() {
fmt.Fprintf(os.Stderr, `Usage: %s check-depends

Compares the Go module dependencies in go.mod against
the Debian packages available in the archive.

Reports:
NEW: Dependencies in go.mod not yet packaged in Debian
RM: Debian packages in d/control no longer needed by go.mod

This command takes no arguments.
`, os.Args[0])
}

err := fs.Parse(args)
if err != nil {
log.Fatal(err)
}

if fs.NArg() > 0 {
fs.Usage()
os.Exit(1)
}

cwd, err := os.Getwd()
if err != nil {
log.Fatalf("error while getting current directory: %s", err)
Expand Down
30 changes: 30 additions & 0 deletions check_depends_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package main

import (
"os"
"os/exec"
"path/filepath"
"reflect"
"strings"
"testing"
)

Expand Down Expand Up @@ -138,3 +140,31 @@ require (
t.Fatalf("Wrong dependencies returned (got %v want %v)", deps, want)
}
}

func TestCheckDependsHelp(t *testing.T) {
// Test that --help flag works and shows usage information
// We run via 'go run' to avoid needing a pre-built binary
cmd := exec.Command("go", "run", ".", "check-depends", "--help")
output, err := cmd.CombinedOutput()

// The -help flag causes flag.ExitOnError to exit with code 0, which exec sees as nil error
if err != nil {
t.Fatalf("check-depends --help failed: %v\nOutput: %s", err, string(output))
}

outputStr := string(output)
expectedStrings := []string{
"Usage:",
"check-depends",
"go.mod",
"d/control",
"NEW:",
"RM:",
}

for _, expected := range expectedStrings {
if !strings.Contains(outputStr, expected) {
t.Errorf("Help output missing expected string %q\nFull output:\n%s", expected, outputStr)
}
}
}
40 changes: 22 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,28 @@ var (
)

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] <command> [flags] <args>\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 <command> -help\",\ne.g. \"%s make -help\"\n", program, program)
fmt.Fprintf(os.Stderr, "\n")
fmt.Fprintf(os.Stderr, `%s

%s is a tool that converts Go packages into Debian package source.

Usage:
%s [globalflags] <command> [flags] <args>

%s commands:
make create a Debian package
search search Debian for already-existing packages
estimate estimate the amount of work for a package
create-salsa-project create a project for hosting Debian packaging
clone clone a Go package from Salsa
check-depends compare go.mod and d/control to check for changes

For backwards compatibility, when no command is specified,
the make command is executed.

To learn more about a command, run "%s <command> -help",
e.g. "%s make -help"

`, buildVersionString(), program, program, program, program, program)
}

func main() {
Expand Down
7 changes: 4 additions & 3 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ func execSearch(args []string) {
fs := flag.NewFlagSet("search", flag.ExitOnError)

fs.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s search <pattern>\n", os.Args[0])
fmt.Fprintf(os.Stderr, "Uses Go's default regexp syntax (https://golang.org/pkg/regexp/syntax/)\n")
fmt.Fprintf(os.Stderr, "Example: %s search 'debi.*'\n", os.Args[0])
fmt.Fprintf(os.Stderr, `Usage: %s search <pattern>
Uses Go's default regexp syntax (https://golang.org/pkg/regexp/syntax/)
Example: %s search 'debi.*'
`, os.Args[0], os.Args[0])
}

err := fs.Parse(args)
Expand Down
3 changes: 2 additions & 1 deletion version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func TestSnapshotVersion(t *testing.T) {
t.Fatalf("Could not write temp file %q: %v", tempfile, err)
}

gitCmdOrFatal(t, tempdir, "init")
// Suppress git hint about default branch name by setting init.defaultBranch
gitCmdOrFatal(t, tempdir, "init", "--initial-branch=master")
gitCmdOrFatal(t, tempdir, "config", "user.email", "unittest@example.com")
gitCmdOrFatal(t, tempdir, "config", "user.name", "Unit Test")
gitCmdOrFatal(t, tempdir, "add", "test")
Expand Down
Loading