forked from aptly-dev/aptly
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request aptly-dev#1411 from schoenherrg/feature/filter-usi…
…ng-file Feature: Support Reading Filter Expressions from a File
- Loading branch information
Showing
19 changed files
with
229 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package cmd | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"strings" | ||
|
||
"github.com/smira/flag" | ||
) | ||
|
||
// 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. | ||
type StringOrFileFlag struct { | ||
value string | ||
} | ||
|
||
func (s *StringOrFileFlag) String() string { | ||
return s.value | ||
} | ||
|
||
func (s *StringOrFileFlag) Set(value string) error { | ||
var err error | ||
s.value, err = GetStringOrFileContent(value) | ||
return err | ||
} | ||
|
||
func (s *StringOrFileFlag) Get() any { | ||
return s.value | ||
} | ||
|
||
func AddStringOrFileFlag(flagSet *flag.FlagSet, name string, value string, usage string) *StringOrFileFlag { | ||
result := &StringOrFileFlag{value: value} | ||
flagSet.Var(result, name, usage) | ||
return result | ||
} | ||
|
||
func GetStringOrFileContent(value string) (string, error) { | ||
if !strings.HasPrefix(value, "@") { | ||
return value, nil | ||
} | ||
|
||
filename := strings.TrimPrefix(value, "@") | ||
var data []byte | ||
var err error | ||
if filename == "-" { // Read from stdin | ||
data, err = io.ReadAll(os.Stdin) | ||
} else { | ||
data, err = os.ReadFile(filename) | ||
} | ||
if err != nil { | ||
return "", err | ||
} | ||
return string(data), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Downloading: http://repo.aptly.info/system-tests/archive.debian.org/debian-security/dists/stretch/updates/Release | ||
|
||
Mirror [mirror36]: http://repo.aptly.info/system-tests/archive.debian.org/debian-security/ stretch/updates successfully added. | ||
You can run 'aptly mirror update mirror36' to download repository contents. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Name: mirror36 | ||
Archive Root URL: http://repo.aptly.info/system-tests/archive.debian.org/debian-security/ | ||
Distribution: stretch/updates | ||
Components: main | ||
Architectures: amd64, arm64, armel, armhf, i386 | ||
Download Sources: no | ||
Download .udebs: no | ||
Filter: nginx | Priority (required) | ||
Filter With Deps: no | ||
Last update: never | ||
|
||
Information from release file: | ||
Acquire-By-Hash: yes | ||
Architectures: amd64 arm64 armel armhf i386 | ||
Codename: stretch | ||
Components: updates/main updates/contrib updates/non-free | ||
Description: Debian 9 Security Updates | ||
|
||
Label: Debian-Security | ||
Origin: Debian | ||
Suite: oldoldstable | ||
Version: 9 |
Oops, something went wrong.