New Upstream Snapshot - golang-github-rakyll-globalconf
Ready changes
Summary
Merged new upstream version: 0.0~git20180912 (was: 0.0~git20140819).
Resulting package
Built on 2022-03-08T10:11 (took 2m29s)
The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:
apt install -t fresh-snapshots golang-github-rakyll-globalconf-dev
Lintian Result
Diff
diff --git a/.travis.yml b/.travis.yml
index fb9efcb..5b77ae6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,2 +1,2 @@
language: go
-go: 1.2
+go: 1.5
diff --git a/README.md b/README.md
index dcbf4dd..363737c 100644
--- a/README.md
+++ b/README.md
@@ -86,7 +86,7 @@ Command line flags will override the environment variables.
~~~ go
opts := globalconf.Options{
- EnvPrefix: "MYAPP_",
+ EnvPrefix: "APPCONF_",
Filename: "/path/to/config",
}
conf, err := globalconf.NewWithOptions(&opts)
diff --git a/debian/changelog b/debian/changelog
index 1e04d69..e35b8b7 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,4 +1,4 @@
-golang-github-rakyll-globalconf (0.0~git20140819-3) UNRELEASED; urgency=medium
+golang-github-rakyll-globalconf (0.0~git20180912-1) UNRELEASED; urgency=medium
[ Alexandre Viau ]
* Point Vcs-* urls to salsa.debian.org.
@@ -7,7 +7,11 @@ golang-github-rakyll-globalconf (0.0~git20140819-3) UNRELEASED; urgency=medium
* Use secure copyright file specification URI.
* Trim trailing whitespace.
- -- Alexandre Viau <aviau@debian.org> Mon, 02 Apr 2018 20:13:55 -0400
+ [ Debian Janitor ]
+ * New upstream snapshot.
+ * Drop patch 0001-reparent-goini-library.patch, present upstream.
+
+ -- Alexandre Viau <aviau@debian.org> Tue, 08 Mar 2022 10:09:51 -0000
golang-github-rakyll-globalconf (0.0~git20140819-2) unstable; urgency=medium
diff --git a/debian/patches/0001-reparent-goini-library.patch b/debian/patches/0001-reparent-goini-library.patch
deleted file mode 100644
index 5ec34ce..0000000
--- a/debian/patches/0001-reparent-goini-library.patch
+++ /dev/null
@@ -1,21 +0,0 @@
-Description: Use original glacjay/goini instead of fork
- Over time the original glacjay/goini repository has come up to date
- with the rakyll/goini fork. This patch switches the dependency back
- to the original repository.
-Author: Tim Potter <tpot@hp.com>
-Bug: https://github.com/rakyll/globalconf/pull/13
----
-This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
-Index: golang-globalconf-0.0~git20140819/globalconf.go
-===================================================================
---- golang-globalconf-0.0~git20140819.orig/globalconf.go
-+++ golang-globalconf-0.0~git20140819/globalconf.go
-@@ -8,7 +8,7 @@ import (
- "path"
- "strings"
-
-- ini "github.com/rakyll/goini"
-+ ini "github.com/glacjay/goini"
- )
-
- const (
diff --git a/debian/patches/series b/debian/patches/series
index 0d1e943..e69de29 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +0,0 @@
-0001-reparent-goini-library.patch
diff --git a/globalconf.go b/globalconf.go
index 57d5dd4..c9b1ced 100644
--- a/globalconf.go
+++ b/globalconf.go
@@ -8,7 +8,7 @@ import (
"path"
"strings"
- ini "github.com/rakyll/goini"
+ ini "github.com/glacjay/goini"
)
const (
@@ -98,14 +98,13 @@ func (g *GlobalConf) Delete(flagSetName, flagName string) error {
return nil
}
-// Parses the config file for the provided flag set.
+// ParseSet parses the config file for the provided flag set.
// If the flags are already set, values are overwritten
// by the values in the config file. Defaults are not set
// if the flag is not in the file.
func (g *GlobalConf) ParseSet(flagSetName string, set *flag.FlagSet) {
set.VisitAll(func(f *flag.Flag) {
- val := getEnv(g.EnvPrefix, flagSetName, f.Name)
- if val != "" {
+ if val, ok := getEnv(g.EnvPrefix, flagSetName, f.Name); ok {
set.Set(f.Name, val)
return
}
@@ -117,7 +116,7 @@ func (g *GlobalConf) ParseSet(flagSetName string, set *flag.FlagSet) {
})
}
-// Parses all the registered flag sets, including the command
+// Parse parses all the registered flag sets, including the command
// line set and sets values from the config file if they are
// not already set.
func (g *GlobalConf) Parse() {
@@ -127,13 +126,12 @@ func (g *GlobalConf) Parse() {
alreadySet[f.Name] = true
})
set.VisitAll(func(f *flag.Flag) {
- // if not already set, set it from dict if exists
+ // if not already set, set it from dict if ok
if alreadySet[f.Name] {
return
}
- val := getEnv(g.EnvPrefix, name, f.Name)
- if val != "" {
+ if val, ok := getEnv(g.EnvPrefix, name, f.Name); ok {
set.Set(f.Name, val)
return
}
@@ -156,10 +154,10 @@ func (g *GlobalConf) ParseAll() {
}
// Looks up variable in environment
-func getEnv(envPrefix, flagSetName, flagName string) string {
+func getEnv(envPrefix, flagSetName, flagName string) (string, bool) {
// If we haven't set an EnvPrefix, don't lookup vals in the ENV
if envPrefix == "" {
- return ""
+ return "", false
}
// Append a _ to flagSetName if it exists.
if flagSetName != "" {
@@ -167,11 +165,13 @@ func getEnv(envPrefix, flagSetName, flagName string) string {
}
flagName = strings.Replace(flagName, ".", "_", -1)
flagName = strings.Replace(flagName, "-", "_", -1)
+ flagSetName = strings.Replace(flagSetName, ".", "_", -1)
+ flagSetName = strings.Replace(flagSetName, "-", "_", -1)
envKey := strings.ToUpper(envPrefix + flagSetName + flagName)
- return os.Getenv(envKey)
+ return os.LookupEnv(envKey)
}
-// Registers a flag set to be parsed. Register all flag sets
+// Register registers a flag set to be parsed. Register all flag sets
// before calling this function. flag.CommandLine is automatically
// registered.
func Register(flagSetName string, set *flag.FlagSet) {
diff --git a/globalconf_test.go b/globalconf_test.go
index f36f74c..fce2cea 100644
--- a/globalconf_test.go
+++ b/globalconf_test.go
@@ -96,6 +96,22 @@ func TestParse_GlobalWithDottedFlagname(t *testing.T) {
}
}
+// Given the need to test overwriting a flag with an environmental variable set to an empty string
+// Reset the flags and clear the env.
+// Set the env var for the c flag to an empty string.
+// Expect flagC to an empty string and not be the value Hello World from the INI file.
+func TestParse_GlobalWithEmptyValue(t *testing.T) {
+ resetForTesting("")
+
+ os.Setenv(envTestPrefix+"C", "")
+ flagC := flag.String("c", "", "")
+
+ parse(t, "./testdata/global.ini", envTestPrefix)
+ if got, want := *flagC, ""; got != want {
+ t.Errorf("got flag = %q, want empty string", got)
+ }
+}
+
func TestParse_GlobalOverwrite(t *testing.T) {
resetForTesting("-b=7.6")
flagB := flag.Float64("b", 0.0, "")
Debdiff
File lists identical (after any substitutions)
No differences were encountered in the control files