From 6197d00f0b76bd0dc31dc9b55b18fa64ee8d1aa9 Mon Sep 17 00:00:00 2001 From: Nidhal Date: Mon, 22 Aug 2016 00:19:41 +0100 Subject: [PATCH 1/4] - Added DumpMyFlags, which return only selected flags to io.writer - Added DumpMyFlagsToPath, which writes only selected flags to path --- out.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/out.go b/out.go index b366f2b..e9f92f8 100644 --- a/out.go +++ b/out.go @@ -50,6 +50,35 @@ func Dump(out io.Writer) error { }) return parser.Serialize(vals, out) } +// DumpMyFlag will write all flags contained in the flags array to the given io.Writer in the flagfile +// serialization format for later parsing. +func DumpMyFlags(myflags []string,out io.Writer) error{ + mtx.Lock() + defer mtx.Unlock() + vals := make(map[string]string) + + flag.VisitAll(func (f *flag.Flag){ + for _,flg := range myflags { + if f.Name == flg { + vals[f.Name] = f.Value.String() + } + } + + }) + return parser.Serialize(vals,out) +} + +func DumpMyFlagsToPath(myflags []string,path string) error{ + fh, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, + 0600) + if err != nil { + return err + } + defer fh.Close() + + return DumpMyFlags(myflags,fh) +} + // DumpToPath simply calls Dump on a new filehandle (O_CREATE|O_TRUNC) for the // given path @@ -61,4 +90,4 @@ func DumpToPath(path string) error { } defer fh.Close() return Dump(fh) -} +} \ No newline at end of file From 703d6c6a3c87efaa332c4f461811321a02727462 Mon Sep 17 00:00:00 2001 From: Nidhal Date: Mon, 22 Aug 2016 00:20:56 +0100 Subject: [PATCH 2/4] - added methods' description in comment --- out.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/out.go b/out.go index e9f92f8..95d9057 100644 --- a/out.go +++ b/out.go @@ -68,6 +68,8 @@ func DumpMyFlags(myflags []string,out io.Writer) error{ return parser.Serialize(vals,out) } +// DumpToPath simply calls DumpMyFlags on a new filehandle (O_CREATE|O_TRUNC) for the +// given path func DumpMyFlagsToPath(myflags []string,path string) error{ fh, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) From 2647eb20c180fbfc3f7336cffa6cfede99cee0bd Mon Sep 17 00:00:00 2001 From: Nidhal Date: Mon, 22 Aug 2016 00:33:05 +0100 Subject: [PATCH 3/4] fixed spacing --- out.go | 1 + 1 file changed, 1 insertion(+) diff --git a/out.go b/out.go index 95d9057..3a24380 100644 --- a/out.go +++ b/out.go @@ -92,4 +92,5 @@ func DumpToPath(path string) error { } defer fh.Close() return Dump(fh) + } \ No newline at end of file From 32a5716ed4656a01bd8d38a9294d9ce20ff69c8e Mon Sep 17 00:00:00 2001 From: Yash Date: Mon, 22 Aug 2016 10:20:09 +0100 Subject: [PATCH 4/4] Revert "fixed spacing" This reverts commit 2647eb20c180fbfc3f7336cffa6cfede99cee0bd. --- out.go | 1 - 1 file changed, 1 deletion(-) diff --git a/out.go b/out.go index 3a24380..95d9057 100644 --- a/out.go +++ b/out.go @@ -92,5 +92,4 @@ func DumpToPath(path string) error { } defer fh.Close() return Dump(fh) - } \ No newline at end of file