Ejemplo n.º 1
0
func Bigquery_v2_JobsList(context Context, args ...string) error {

	usageFunc := func() {
		usageBits := fmt.Sprintf("gcloud_apis %s", context.InvocationMethod)

		usageBits += " [--allUsers=VALUE]"

		usageBits += " [--maxResults=VALUE]"

		usageBits += " [--pageToken=VALUE]"

		usageBits += " [--projection=VALUE]"

		usageBits += " [--stateFilter=VALUE]"

		fmt.Fprintf(os.Stderr, "Usage:\n\t%s\n", usageBits)
		os.Exit(1)
	}

	api_service, err := api_client.New(context.Client)
	if err != nil {
		return err
	}
	service := api_client.NewJobsService(api_service)

	queryParamNames := map[string]bool{
		"allUsers":    false,
		"maxResults":  false,
		"pageToken":   false,
		"projection":  false,
		"stateFilter": false,
	}

	args, flagValues, err := commands_util.ExtractFlagValues(args)
	if err != nil {
		return err
	}

	for k, r := range queryParamNames {
		if _, ok := flagValues[k]; r && !ok {
			return fmt.Errorf("missing required flag %q", "--"+k)
		}
	}

	// Only positional arguments should remain in args.
	if len(args) != 1 {
		usageFunc()
	}

	expectedParams := []string{
		"projectId",
	}
	paramValues := strings.Split(args[0], "/")
	if len(paramValues) != len(expectedParams) {
		return commands_util.ErrForWrongParams(expectedParams, paramValues, args)
	}

	param_projectId := paramValues[0]

	call := service.List(param_projectId)

	// Set query parameters.
	if value, ok := flagValues["allUsers"]; ok {
		query_allUsers, err := commands_util.ConvertValue_bool(value)
		if err != nil {
			return err
		}
		call.AllUsers(query_allUsers)
	}
	if value, ok := flagValues["maxResults"]; ok {
		query_maxResults, err := commands_util.ConvertValue_int64(value)
		if err != nil {
			return err
		}
		call.MaxResults(query_maxResults)
	}
	if value, ok := flagValues["pageToken"]; ok {
		query_pageToken, err := commands_util.ConvertValue_string(value)
		if err != nil {
			return err
		}
		call.PageToken(query_pageToken)
	}
	if value, ok := flagValues["projection"]; ok {
		query_projection, err := commands_util.ConvertValue_string(value)
		if err != nil {
			return err
		}
		call.Projection(query_projection)
	}
	if value, ok := flagValues["stateFilter"]; ok {
		query_stateFilter, err := commands_util.ConvertValue_string(value)
		if err != nil {
			return err
		}
		call.StateFilter(query_stateFilter)
	}

	var response *api_client.JobList
	response, err = call.Do()
	if err != nil {
		return err
	}

	err = commands_util.PrintResponse(response)
	if err != nil {
		return err
	}

	return nil
}
Ejemplo n.º 2
0
func Developerprojects_v1_ProjectsCreate(context Context, args ...string) error {

	usageFunc := func() {
		usageBits := fmt.Sprintf("gcloud_apis %s", context.InvocationMethod)

		usageBits += " [REQUEST_FILE|-] [--REQUEST_KEY=VALUE]*"

		usageBits += " [--appengineStorageLocation=VALUE]"

		usageBits += " [--createAppengineProject=VALUE]"

		fmt.Fprintf(os.Stderr, "Usage:\n\t%s\n", usageBits)
		os.Exit(1)
	}

	api_service, err := api_client.New(context.Client)
	if err != nil {
		return err
	}
	service := api_client.NewProjectsService(api_service)

	queryParamNames := map[string]bool{
		"appengineStorageLocation": false,
		"createAppengineProject":   false,
	}

	args, flagValues, err := commands_util.ExtractFlagValues(args)
	if err != nil {
		return err
	}

	for k, r := range queryParamNames {
		if _, ok := flagValues[k]; r && !ok {
			return fmt.Errorf("missing required flag %q", "--"+k)
		}
	}

	// Only positional arguments should remain in args.
	if len(args) == 0 || len(args) > 2 {
		usageFunc()
	}

	request := &api_client.Project{}
	if len(args) == 2 {
		err = commands_util.PopulateRequestFromFilename(&request, args[1])
		if err != nil {
			return err
		}
	}

	// Any flags that aren't query parameters are applied to the request.
	keyValues := map[string]string{}
	for k, v := range flagValues {
		if _, ok := queryParamNames[k]; !ok {
			keyValues[k] = v
		}
	}

	err = commands_util.OverwriteRequestWithValues(&request, keyValues)
	if err != nil {
		return err
	}

	expectedParams := []string{}
	paramValues := strings.Split(args[0], "/")
	if len(paramValues) != len(expectedParams) {
		return commands_util.ErrForWrongParams(expectedParams, paramValues, args)
	}

	call := service.Create(
		request,
	)

	// Set query parameters.
	if value, ok := flagValues["appengineStorageLocation"]; ok {
		query_appengineStorageLocation, err := commands_util.ConvertValue_string(value)
		if err != nil {
			return err
		}
		call.AppengineStorageLocation(query_appengineStorageLocation)
	}
	if value, ok := flagValues["createAppengineProject"]; ok {
		query_createAppengineProject, err := commands_util.ConvertValue_bool(value)
		if err != nil {
			return err
		}
		call.CreateAppengineProject(query_createAppengineProject)
	}

	var response *api_client.Project
	response, err = call.Do()
	if err != nil {
		return err
	}

	err = commands_util.PrintResponse(response)
	if err != nil {
		return err
	}

	return nil
}
Ejemplo n.º 3
0
func Bigquery_v2_DatasetsDelete(context Context, args ...string) error {

	usageFunc := func() {
		usageBits := fmt.Sprintf("gcloud_apis %s", context.InvocationMethod)

		usageBits += " [--deleteContents=VALUE]"

		fmt.Fprintf(os.Stderr, "Usage:\n\t%s\n", usageBits)
		os.Exit(1)
	}

	api_service, err := api_client.New(context.Client)
	if err != nil {
		return err
	}
	service := api_client.NewDatasetsService(api_service)

	queryParamNames := map[string]bool{
		"deleteContents": false,
	}

	args, flagValues, err := commands_util.ExtractFlagValues(args)
	if err != nil {
		return err
	}

	for k, r := range queryParamNames {
		if _, ok := flagValues[k]; r && !ok {
			return fmt.Errorf("missing required flag %q", "--"+k)
		}
	}

	// Only positional arguments should remain in args.
	if len(args) != 1 {
		usageFunc()
	}

	expectedParams := []string{
		"projectId",
		"datasetId",
	}
	paramValues := strings.Split(args[0], "/")
	if len(paramValues) != len(expectedParams) {
		return commands_util.ErrForWrongParams(expectedParams, paramValues, args)
	}

	param_projectId := paramValues[0]
	param_datasetId := paramValues[1]

	call := service.Delete(param_projectId, param_datasetId)

	// Set query parameters.
	if value, ok := flagValues["deleteContents"]; ok {
		query_deleteContents, err := commands_util.ConvertValue_bool(value)
		if err != nil {
			return err
		}
		call.DeleteContents(query_deleteContents)
	}

	err = call.Do()
	if err != nil {
		return err
	}

	return nil
}