mirror of
https://github.com/gopasspw/gopass.git
synced 2026-05-30 11:18:48 +02:00
23dae78b13
Addresses I-2 from the code quality audit: make gopass's exit codes
discoverable and stable for scripting users.
Changes:
- internal/action/exit/errors.go: replace iota with explicit integer
constants so that inserting future codes cannot silently renumber
existing ones; add PrintExitCodes(io.Writer) that renders a
tab-aligned table of all 22 codes.
- main.go: add --exit-codes app-level flag; a Before hook calls
PrintExitCodes and exits 0 when the flag is present.
- docs/exit-codes.md: new reference page with the full table and
per-command breakdowns for show, insert, generate, find, delete,
audit, fsck, and doctor.
- docs/commands/{show,insert,generate,find,delete,audit,fsck}.md:
each gets a short '## Exit codes' section pointing at the reference
page.
- ARCHITECTURE.md: expand the exit-package paragraph with a pointer
to the docs and the stable-contract guarantee.
- tests/exitcodes_test.go: integration test asserting gopass
--exit-codes exits 0 and prints representative codes/names.
- main_test.go: fix pre-existing count assertion (42→43, doctor was
added in an earlier commit) and add .audit to commandsWithError
(audit now returns an error when weak passwords are found, as fixed
in B-7).
25 lines
535 B
Go
25 lines
535 B
Go
package tests
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestExitCodesFlag(t *testing.T) {
|
|
ts := newTester(t)
|
|
defer ts.teardown()
|
|
|
|
out, err := ts.run("--exit-codes")
|
|
require.NoError(t, err)
|
|
|
|
// Verify a representative selection of codes and names appear in the output.
|
|
assert.Contains(t, out, "0")
|
|
assert.Contains(t, out, "OK")
|
|
assert.Contains(t, out, "10")
|
|
assert.Contains(t, out, "NotFound")
|
|
assert.Contains(t, out, "21")
|
|
assert.Contains(t, out, "Doctor")
|
|
}
|