From b96c506dcef5c440bf8ea184df8fd54eb6f168d1 Mon Sep 17 00:00:00 2001 From: Victor Vrantchan Date: Mon, 29 May 2017 21:17:53 -0400 Subject: [PATCH] support writing file to stdout (#186) --- cmd/mdmctl/get.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/cmd/mdmctl/get.go b/cmd/mdmctl/get.go index 7cd33966..3bf12c59 100644 --- a/cmd/mdmctl/get.go +++ b/cmd/mdmctl/get.go @@ -258,7 +258,7 @@ func (cmd *getCommand) getBlueprints(args []string) error { func (cmd *getCommand) getProfiles(args []string) error { flagset := flag.NewFlagSet("profiles", flag.ExitOnError) var ( - flProfilePath = flagset.String("f", "", "filename of profile to write") + flProfilePath = flagset.String("f", "-", "filename of profile to write") flIdentifier = flagset.String("id", "", "profile Identifier") ) flagset.Usage = usageFor(flagset, "mdmctl get blueprints [flags]") @@ -286,17 +286,27 @@ func (cmd *getCommand) getProfiles(args []string) error { if *flIdentifier != "" && *flProfilePath != "" { p := profiles[0] - newProfileFile, err := os.Create(*flProfilePath) - if err != nil { - return err + var output *os.File + { + if *flProfilePath == "-" { + output = os.Stdout + } else { + newProfileFile, err := os.Create(*flProfilePath) + if err != nil { + return err + } + defer newProfileFile.Close() + output = newProfileFile + } } - defer newProfileFile.Close() - _, err = newProfileFile.Write([]byte(p.Mobileconfig)) + _, err = output.Write([]byte(p.Mobileconfig)) if err != nil { return err } - fmt.Printf("\nwrote profile id %s to: %s\n", p.Identifier, *flProfilePath) + if *flProfilePath != "-" { + fmt.Printf("\nwrote profile id %s to: %s\n", p.Identifier, *flProfilePath) + } if len(profiles) > 1 { fmt.Println("WARNING: more than one Profile returned; only saved first")