Ejemplo n.º 1
0
// runAirfieldPut invokes the configured plugins to put airfield data from source to dest.
func runAirfieldPut(cmd *commander.Command, args []string) {
	var err error
	if len(args) != 1 {
		fmt.Fprintf(os.Stderr, "failed to put airfield data :: no destination given\n")
		return
	}
	cfg, _ := config.Get()
	pluginID := args[0]
	destPlugin, err := plugin.GetAirfielder(pluginID, cfg)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to get plugin '%v' :: %v\n", pluginID, err)
		return
	}
	afield, _ := plugin.GetAirfielder("", cfg)
	airfields, err := afield.(airfield.Airfielder).GetAirfield(strings.Split(*region, ","), time.Time{})
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to get airfield :: %v\n", err)
		return
	}
	glog.V(5).Infof("putting %v airfields", len(airfields))
	glog.V(20).Infof("%v", airfields)
	if len(airfields) > 0 {
		err = destPlugin.(airfield.Airfielder).PutAirfield(airfields)
		if err != nil {
			fmt.Fprintf(os.Stderr, "failed to put airfields :: %v\n", err)
			return
		}
	}
	fmt.Printf("pushed %v airfields into %v\n", len(airfields), pluginID)
}
Ejemplo n.º 2
0
// runAirfieldGet invokes the configured plugin and outputs airfield data.
func runAirfieldGet(cmd *commander.Command, args []string) {
	var err error
	cfg, _ := config.Get()
	afield, err := plugin.GetAirfielder("", cfg)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to get airfield plugin :: %v\n", err)
		return
	}
	tafter := time.Time{}
	if *after != "" {
		tafter, err = time.Parse("2006-01-02", *after)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to get airfield :: %v\n", err)
			return
		}
	}
	airfields, err := afield.(airfield.Airfielder).GetAirfield(strings.Split(*region, ","), tafter)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to get airfield :: %v\n", err)
		return
		// FIXME: must return -1, but no way now to check this in test
	}
	glog.V(5).Infof("airfield get with args '%v' got %d results", args, len(airfields))
	glog.V(20).Infof("%+v", airfields)
	fmt.Printf("%v", util.Struct2CSV(airfields))
}