Skip to content

Conversation

opencoff
Copy link

  • add a new abbreviation generator (abbrev.go) with tests
  • teach flag.go to build an abbrev table for long args and look it up and add tests to verify new behavior
  • Fix "spurious new line" error from use of Println()

* add a new abbreviation generator (abbrev.go) with tests
* teach flag.go to build an abbrev table for long args and look it up
  and add tests to verify new behavior
* Fix "spurious new line" error from use of Println()
@CLAassistant
Copy link

CLAassistant commented Dec 30, 2022

CLA assistant check
All committers have signed the CLA.

@@ -7,7 +7,7 @@ package pflag_test
import (
"fmt"

"github.com/spf13/pflag"
"github.com/opencoff/pflag"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems to be a left behind debug

@@ -16,7 +16,7 @@ pflag is a drop-in replacement of Go's native flag package. If you import
pflag under the name "flag" then all code should continue to function
with no changes.

import flag "github.com/spf13/pflag"
import flag "github.com/opencoff/pflag"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@@ -1314,7 +1314,7 @@ func TestPrintDefaults(t *testing.T) {
func TestVisitAllFlagOrder(t *testing.T) {
fs := NewFlagSet("TestVisitAllFlagOrder", ContinueOnError)
fs.SortFlags = false
// https://github.com/spf13/pflag/issues/120
// https://github.com/opencoff/pflag/issues/120

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@@ -1,3 +1,3 @@
module github.com/spf13/pflag
module github.com/opencoff/pflag

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

}

// make an assert() function for use in environment 't' and return it
func newAsserter(t *testing.T) func(cond bool, msg string, args ...interface{}) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.Helper is missing here

Suggested change
func newAsserter(t *testing.T) func(cond bool, msg string, args ...interface{}) {
func newAsserter(t *testing.T) func(cond bool, msg string, args ...interface{}) {
t.Helper()

Copy link
Collaborator

@tomasaschan tomasaschan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks (mostly, but not entirely) ok, given that line comments are addressed appropriately.

I'm not convinced the feature is a good idea, though.

My main reason to hesitate is that this is makes it a lot easier for users of pflag to, unintendedly, introduce changes in their CLI contracts that are breaking to their users. Most obviously, adding a new flag that shares a prefix with an existing one, will break all scripts (or shell history) that use an abbreviation which is no longer unambiguous.

One could argue that it's not pflag's responsibility to ensure our users don't break their users, but having this feature as is - enabled and non-optional - effectively makes it harder for our users not to. I'm not convinced of the value of this feature either way, but I think it needs to, at the very least, be behind a feature flag and turned off by default.

I don't know if pflag already has a mechanism for users to toggle features on or off. If there is no such mechanism, building one is probably a good scope for a separate PR independent of this one.

Comment on lines +1 to +8
// abbrev.go - generate abbreviations from a wordlist
//
// (c) 2014 Sudhi Herle <sw-at-herle.net>
//
// Placed in the Public Domain
// This software does not come with any express or implied
// warranty; it is provided "as is". No claim is made to its
// suitability for any purpose.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this code copied from somewhere else? If so where?

Might just be me, but I also find the combination of a copyright header and "added to the public domain" confusing. Is it copyright protected or not? What are the expectations on anyone finding this piece of code and wanting to use it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original inspiration came from perl's abbrev.pm; IIRC I picked the same terms as that module.

// Abbrev() returns:
// {
// "hello": "hello",
// "hell": "hell"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should read "hell": "hello",?

case 2:
delete(table, ab)
default:
goto next
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. No fan of this. Why not use a (possibly labeled) break?


go 1.12
go 1.24.3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is, if intended, a (significantly) breaking change. Is it necessary?

@opencoff
Copy link
Author

The implementation looks (mostly, but not entirely) ok, given that line comments are addressed appropriately.

I'm not convinced the feature is a good idea, though.

My main reason to hesitate is that this is makes it a lot easier for users of pflag to, unintendedly, introduce changes in their CLI contracts that are breaking to their users. Most obviously, adding a new flag that shares a prefix with an existing one, will break all scripts (or shell history) that use an abbreviation which is no longer unambiguous.

One could argue that it's not pflag's responsibility to ensure our users don't break their users, but having this feature as is - enabled and non-optional - effectively makes it harder for our users not to. I'm not convinced of the value of this feature either way, but I think it needs to, at the very least, be behind a feature flag and turned off by default.

I don't know if pflag already has a mechanism for users to toggle features on or off. If there is no such mechanism, building one is probably a good scope for a separate PR independent of this one.

Your points re defaulting to "on" leading to breakages is valid. Perhaps there is no point in pursuing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants