~seirdy/moac

083ee7e0a03a2590abdca38921f45a9c5bc41662 — Pranjal Kole 2 years ago f269686
CLI: warn if grapheme clusters are detected

The uniseg package was used to detect grapheme clusters, because it is
the only one which supports it at the moment.

[Ticket: 19]
2 files changed, 18 insertions(+), 0 deletions(-)

M cmd/moac-pwgen/main.go
M cmd/moac/main.go
M cmd/moac-pwgen/main.go => cmd/moac-pwgen/main.go +9 -0
@@ 12,6 12,7 @@ import (
	"git.sr.ht/~seirdy/moac/v2/internal/sanitize"
	"git.sr.ht/~seirdy/moac/v2/pwgen"
	"git.sr.ht/~sircmpwn/getopt"
	"github.com/rivo/uniseg"
)

const (


@@ 152,6 153,14 @@ func main1() int {
		return 1
	}

	graphemes := uniseg.NewGraphemes(strings.Join(args, ""))
	for graphemes.Next() {
		if len(graphemes.Runes()) > 1 {
			fmt.Fprintf(os.Stderr, "warning: charsets contain grapheme clusters, will be treated as distinct codepoints\n")
			break
		}
	}

	pwr.CharsetsWanted = charsets.ParseCharsets(setCharsetNames(args))
	pw, err := pwgen.GenPW(pwr)


M cmd/moac/main.go => cmd/moac/main.go +9 -0
@@ 12,6 12,7 @@ import (
	"git.sr.ht/~seirdy/moac/v2/internal/cli"
	"git.sr.ht/~sircmpwn/getopt"
	"golang.org/x/term"
	"github.com/rivo/uniseg"
)

const (


@@ 159,6 160,14 @@ func getOutput() (output float64, exitEarly bool, err error) {
		return output, exitEarly, fmt.Errorf("moac: %w", err)
	}

	graphemes := uniseg.NewGraphemes(givens.Password)
	for graphemes.Next() {
		if len(graphemes.Runes()) > 1 {
			fmt.Fprintf(os.Stderr, "warning: charsets contain grapheme clusters, will be treated as distinct codepoints\n")
			break
		}
	}

	cmd := strengthCmd

	if len(os.Args) > optind {