Skip to content

Commit

Permalink
refactor dataset get proposal code
Browse files Browse the repository at this point in the history
  • Loading branch information
Consolethinks authored and consolethinks committed Jul 15, 2024
1 parent 55a1b86 commit 7c12719
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions cmd/commands/datasetGetProposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"log"
"net/http"
"os"
"time"

"github.com/fatih/color"
Expand All @@ -29,8 +28,8 @@ For further help see "` + MANUAL + `"`,

const APP = "datasetGetProposal"

var APIServer string
var env string
var APIServer string = PROD_API_SERVER
var env string = "production"

// pass parameters
userpass, _ := cmd.Flags().GetString("user")
Expand Down Expand Up @@ -61,30 +60,24 @@ For further help see "` + MANUAL + `"`,
// check for program version only if running interactively
datasetUtils.CheckForNewVersion(client, APP, VERSION)

if devenvFlag {
APIServer = DEV_API_SERVER
env = "dev"
}
if testenvFlag {
APIServer = TEST_API_SERVER
env = "test"
} else if devenvFlag {
APIServer = DEV_API_SERVER
env = "dev"
} else {
APIServer = PROD_API_SERVER
env = "production"
}

color.Set(color.FgGreen)
log.Printf("You are about to retrieve the proposal information from the === %s === data catalog environment...", env)
color.Unset()

ownerGroup := ""

//TODO cleanup text formatting:
if len(args) == 1 {
ownerGroup = args[0]
} else {
log.Println("invalid number of args")
return
if len(args) < 1 || len(args) > 1 {
log.Fatalln("invalid number of args")
}
ownerGroup := args[0]

auth := &datasetUtils.RealAuthenticator{}
user, accessGroups := datasetUtils.Authenticate(auth, client, APIServer, &token, &userpass)
Expand All @@ -95,17 +88,15 @@ For further help see "` + MANUAL + `"`,

// proposal is of type map[string]interface{}

if len(proposal) > 0 {
if fieldname != "" {
fmt.Println(proposal[fieldname])
} else {
pretty, _ := json.MarshalIndent(proposal, "", " ")
fmt.Printf("%s\n", pretty)
}
os.Exit(0)
if len(proposal) <= 0 {
log.Fatalf("No Proposal information found for group %v\n", ownerGroup)
}

if fieldname != "" {
fmt.Println(proposal[fieldname])
} else {
log.Printf("No Proposal information found for group %v\n", ownerGroup)
os.Exit(1)
pretty, _ := json.MarshalIndent(proposal, "", " ")
fmt.Printf("%s\n", pretty)
}
},
}
Expand Down

0 comments on commit 7c12719

Please sign in to comment.