mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-05 08:55:51 +08:00
63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
"text/tabwriter"
|
|
|
|
"github.com/micromdm/micromdm/platform/appstore"
|
|
)
|
|
|
|
type appsTableOutput struct{ w *tabwriter.Writer }
|
|
|
|
func (out *appsTableOutput) BasicHeader() {
|
|
fmt.Fprintf(out.w, "Name\tManifestURL\n")
|
|
}
|
|
|
|
func (out *appsTableOutput) BasicFooter() {
|
|
out.w.Flush()
|
|
}
|
|
|
|
func (cmd *getCommand) getApps(args []string) error {
|
|
flagset := flag.NewFlagSet("apps", flag.ExitOnError)
|
|
var (
|
|
flNameFilter = flagset.String("name", "", "specify the name of the app to get full details")
|
|
flOutputPath = flagset.String("f", "-", "path to save file to. defaults to stdout.")
|
|
)
|
|
flagset.Usage = usageFor(flagset, "mdmctl get apps [flags]")
|
|
if err := flagset.Parse(args); err != nil {
|
|
return err
|
|
}
|
|
ctx := context.Background()
|
|
apps, err := cmd.appsvc.ListApplications(ctx, appstore.ListAppsOption{
|
|
FilterName: []string{*flNameFilter},
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if *flNameFilter != "" && (len(apps) != 0) {
|
|
payload := apps[0].Payload
|
|
if *flOutputPath == "-" {
|
|
fmt.Println(string(payload))
|
|
return nil
|
|
}
|
|
return ioutil.WriteFile(*flOutputPath, payload, 0644)
|
|
}
|
|
rURL, err := repoURL(cmd.config.ServerURL)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
|
|
out := appsTableOutput{w}
|
|
out.BasicHeader()
|
|
defer out.BasicFooter()
|
|
for _, a := range apps {
|
|
manifestURL := rURL + "/" + a.Name
|
|
fmt.Fprintf(out.w, "%s\t%s\n", a.Name, manifestURL)
|
|
}
|
|
return nil
|
|
}
|