You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If there is any chance of getting this feature merged, I would clean up our code a bit and make a PR.
What do you think?
Detailed Description
For us it's mainly important that this works in the mirror create and mirror edit subcommands' -filter argument.
However, there are also other places in Aptly where a package query can be provided, so there is the question of whether we should support it everywhere for consistency, e.g.
supports multiple queries, so should we allow the @file syntax there (then you could theoretically specify multiple different files and even mix it with plain queries like @file1 vim @file2 ...)?
Also, this is technically a breaking change, though I doubt many users have existing filters that start with @ because that is not a valid character for a Debian package name and thus would not match any packages.
Context
The reason we have implemented this is that we have filter expressions that exceed the command line length limit.
Possible Implementation
Since the flag library used by Aptly (smira/flag) allows creating custom types of flags, I just made a StringOrFileFlag like this:
// StringOrFileFlag is a custom flag type that can handle both string input and file input.// If the input starts with '@', it is treated as a filename and the contents are read from the file.// If the input is '@-', the contents are read from stdin.typeStringOrFileFlagstruct {
valuestring
}
func (s*StringOrFileFlag) Set(valuestring) error {
varerrerrors.value, err=GetStringOrFileContent(value)
returnerr
}
funcGetStringOrFileContent(valuestring) (string, error) {
if!strings.HasPrefix(value, "@") {
returnvalue, nil
}
filename:=strings.TrimPrefix(value, "@")
vardata []bytevarerrerroriffilename=="-" { // Read from stdindata, err=io.ReadAll(os.Stdin)
} else {
data, err=os.ReadFile(filename)
}
iferr!=nil {
return"", err
}
returnstring(data), nil
}
// ...
This way, the file/error handling logic is in one place and you can just use it like this without having to change any other code in other places:
- cmd.Flag.String("filter", "", "filter packages in mirror")+ AddStringOrFileFlag(&cmd.Flag, "filter", "", "filter packages in mirror, use '@file' to read filter from file or '@-' for stdin")
Your Environment
N/A
The text was updated successfully, but these errors were encountered:
We have an internal patch for Aptly to support reading filter expressions from a file or from stdin. For example:
If there is any chance of getting this feature merged, I would clean up our code a bit and make a PR.
What do you think?
Detailed Description
For us it's mainly important that this works in the
mirror create
andmirror edit
subcommands'-filter
argument.However, there are also other places in Aptly where a package query can be provided, so there is the question of whether we should support it everywhere for consistency, e.g.
supports multiple queries, so should we allow the
@file
syntax there (then you could theoretically specify multiple different files and even mix it with plain queries like@file1 vim @file2 ...
)?Also, this is technically a breaking change, though I doubt many users have existing filters that start with
@
because that is not a valid character for a Debian package name and thus would not match any packages.Context
The reason we have implemented this is that we have filter expressions that exceed the command line length limit.
Possible Implementation
Since the flag library used by Aptly (
smira/flag
) allows creating custom types of flags, I just made aStringOrFileFlag
like this:This way, the file/error handling logic is in one place and you can just use it like this without having to change any other code in other places:
Your Environment
N/A
The text was updated successfully, but these errors were encountered: