Exemple #1
0
func Show(cmd *cobra.Command, args []string) {
	log.Verbose(verbose)

	if len(args) < 1 {
		//fmt.Fprintln(os.Stderr, "missing arguments")
		cmd.Usage()
		return
	}

	stub, err := pub.GetStubAndLoginFromCfg(cfg, &info)
	if err != nil {
		fmt.Fprintln(os.Stderr, "failed to Login\n", "error:", err.Error())
		return
	}
	if bShowRes {
		err = showRes(stub, info.ID, args[0])
	} else {
		err = showManifest(stub, info.ID, args[0])
	}

	if err != nil {
		fmt.Fprintln(os.Stderr, "error:", err.Error())
	}

}
Exemple #2
0
//参数:
//-name :资源名
//-ver :版本
//清除给定资源给定版本之前的所有资源
func Clear() error {
	var info pub.LoginInfo
	stub, err := pub.GetStubAndLoginFromCfg(*cfg, &info)
	if err != nil {
		return err
	}
	if *appName != "" {
		clearManifest(stub, info.ID, *appName, *ver)
	}
	return clearRes(stub, info.ID, *name, *ver)
}
Exemple #3
0
//参数:
//-name :资源名
func Show() error {
	fmt.Printf("Push: name=%s\r\n", *name)
	var info pub.LoginInfo
	stub, err := pub.GetStubAndLoginFromCfg(*cfg, &info)
	if err != nil {
		return err
	}
	if *appName != "" {
		showManifest(stub, info.ID, *appName)
	}
	return showRes(stub, info.ID, *name)
}
Exemple #4
0
func Release(cmd *cobra.Command, args []string) {
	log.Verbose(verbose)

	if len(args) < 1 {
		// fmt.Fprintln(os.Stderr, "missing AppName")
		cmd.Usage()
		return
	}

	res := args[0]
	var v int
	var err error
	if len(args) == 2 {
		v, err = strconv.Atoi(args[1])
	} else {
		v = -1
	}

	if err != nil {
		if args[1] == "last" {
			v = -1
		} else {
			fmt.Fprintln(os.Stderr, "invalid version\n", cmd.Help())
			return
		}
	}

	err = nil
	stub, err := pub.GetStubAndLoginFromCfg(cfg, &info)
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
		return
	}

	if !relRes {
		err = ReleaseManifest(stub, info.ID, res, v)

	} else {
		err = ReleaseRes(stub, info.ID, res, v)
	}

	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
	}
}
Exemple #5
0
//参数:
//-name :资源名
//-ver:资源的版本,缺省是自动生成
func Release() error {
	//if *name == "" {
	//	if flag.NArg() < 2 {
	//		return errors.New("Res show name")
	//	}
	//	*name = flag.Arg(1)
	//}

	var info pub.LoginInfo
	stub, err := pub.GetStubAndLoginFromCfg(*cfg, &info)
	if err != nil {
		return err
	}
	if *appName != "" {
		return ReleaseManifest(stub, info.ID, *appName, *ver)
	}
	return ReleaseRes(stub, info.ID, *name, *ver)
}
Exemple #6
0
//参数:
//-name :资源名
//-file :文件名
//-ver:资源的版本,缺省是自动生成
func Push(cmd *cobra.Command, args []string) {
	if verbose {
		log.Verbose(verbose)
	}

	//fmt.Println("verbose: ", verbose)
	stub, err := pub.GetStubAndLoginFromCfg(cfg, &info)
	if err != nil {
		fmt.Fprintln(os.Stderr, "failed to login", err.Error())
		return
	}

	if len(args) == 0 {
		if err := PushManifest(stub, ManifestFile); err != nil {
			fmt.Fprintln(os.Stderr, err.Error())
		}
	} else if len(args) >= 2 {
		var id string
		var v int
		if len(args) == 3 {
			v, err = strconv.Atoi(args[2])
			if err != nil {
				if args[2] == "last" {
					v = -1
				} else {
					fmt.Fprintln(os.Stderr, "invalid version number:", args[2])
					cmd.Usage()
					return
				}
			}
		}

		id, err = PushRes(stub, info.ID, args[0], args[1], v)
		if err != nil {
			fmt.Fprintf(os.Stderr, err.Error())
			return
		}
		log.Info("id:", id, "\npushed ok")
	}
}
Exemple #7
0
//参数:
//-name :资源名
//-file :文件名
//-ver:资源的版本,缺省是自动生成
func Push() error {
	if flag.NArg() < 2 {
		return errors.New("Res 资源名")
	}

	var info pub.LoginInfo
	stub, err := pub.GetStubAndLoginFromCfg(*cfg, &info)
	if err != nil {
		return fmt.Errorf("GetStubAndLoginFromCfg err:%s", err.Error())
	}

	filename := flag.Arg(1)
	//fmt.Printf("Push:filename=%s name=%s, cfg=%s, ver=%d\r\n", filename, *name, *cfg, *ver)
	if strings.HasSuffix(filename, ManifestFile) {
		return PushManifest(stub, filename)
	}

	var id string
	id, err = PushRes(stub, info.ID, *name, filename, *ver)
	fmt.Println("resource current id is ", id)
	return err
}
Exemple #8
0
func Clear(cmd *cobra.Command, args []string) {
	log.Verbose(verbose)

	if len(args) != 2 {
		//fmt.Fprintln(os.Stderr, "invalid num of aruguments")
		cmd.Usage()
		return
	}

	stub, err := pub.GetStubAndLoginFromCfg(cfg, &info)
	if err != nil {
		fmt.Fprintln(os.Stderr, "failed to login", err.Error())
		return
	}

	v, err := strconv.Atoi(args[1])
	if err != nil {
		if args[1] == "last" {
			v = -1
		} else if args[1] == "release" {
			v = -2
		} else {
			fmt.Fprintln(os.Stderr, "invalid verison number", err.Error())
			return
		}
	}

	if v != -1 && v != -2 && (v-4) < 0 {
		log.Info("no need to clear")
		return
	}
	if clsRes {
		clearRes(stub, info.ID, args[0], v)
	} else {
		clearManifest(stub, info.ID, args[0], v)
	}
}