From 6693975f5ee27310ee186f956f08dba598f34ce9 Mon Sep 17 00:00:00 2001 From: Sergey Kamardin Date: Thu, 17 Dec 2020 21:06:03 +0300 Subject: [PATCH] Copy() helper implementation --- flagutil.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/flagutil.go b/flagutil.go index a048790..12d48ab 100644 --- a/flagutil.go +++ b/flagutil.go @@ -454,6 +454,14 @@ func MergeInto(super *flag.FlagSet, setup func(*flag.FlagSet)) { }) } +// Copy defines all flags from src with dst. +// It panics on any flag name collision. +func Copy(dst, src *flag.FlagSet) { + src.VisitAll(func(f *flag.Flag) { + dst.Var(f.Value, f.Name, f.Usage) + }) +} + // CombineSets combines given sets into a third one. // Every collided flags are combined into third one in a way that setting value // to it sets value of both original flags.