diff --git a/deploy.go b/deploy.go index 4a0a4b5..50a64eb 100644 --- a/deploy.go +++ b/deploy.go @@ -10,6 +10,7 @@ import ( . "harness/utils" "os" "strings" + "time" ) func DeployProject(c *cli.Context) error { @@ -21,8 +22,8 @@ func DeployProject(c *cli.Context) error { if err != nil { return err } - - fmt.Printf("Loaded framework: %s\n", GetColoredText(framework, color.FgCyan)) + ProjectprogressBar("Loading Project Info...") + fmt.Printf("\nLoaded framework: %s\n", GetColoredText(framework, color.FgCyan)) fmt.Printf("Loaded language: %s\n", GetColoredText(language, color.FgCyan)) hasDockerfile, err := checkDockerfile() @@ -44,8 +45,9 @@ func DeployProject(c *cli.Context) error { if err != nil { return err } + ProjectprogressBar("Creating Dockerfile...") color.Set(color.FgGreen) - fmt.Println("šŸ‹ Dockerfile created.") + fmt.Println("\nšŸ‹ Dockerfile created.") color.Unset() hasDockerfile = true } @@ -56,7 +58,7 @@ func DeployProject(c *cli.Context) error { return err } - fmt.Print("Do you want to proceed deploying using Harness? (y/n): ") + fmt.Print("\nDo you want to proceed deploying using Harness? (y/n): ") var proceed string fmt.Scanln(&proceed) @@ -65,7 +67,7 @@ func DeployProject(c *cli.Context) error { return nil } - orgName := promptUser("Org Name (default)", "default") + orgName := promptUser("\nOrg Name (default)", "default") projectName := promptUser("Project Name (default_project)", "default_project") _, err = CheckOrgExistsAndCreate(c, orgName) @@ -85,16 +87,16 @@ func DeployProject(c *cli.Context) error { return err } - fmt.Print("Do you want to use the Harness Code Repository for code hosting? (y/n): ") + fmt.Print("\n\nDo you want to use the Harness Code Repository for code hosting? (y/n): ") var useHarnessRepo string fmt.Scanln(&useHarnessRepo) if useHarnessRepo == "y" { - fmt.Printf("Already using Harness Code Repository for code hosting ? (y/n): ") + fmt.Printf("\nAlready using Harness Code Repository for code hosting ? (y/n): ") var useHarnessCodeRepo string fmt.Scanln(&useHarnessCodeRepo) if useHarnessCodeRepo == "y" { - fmt.Println("Provide the repository Name: ") + fmt.Println("\nProvide the repository Name: ") repoName := promptUser("Repository Name", "default_repo") globals.RepoName = repoName } else { @@ -108,8 +110,12 @@ func DeployProject(c *cli.Context) error { } CreatePipeline() RemoveTempFiles() - fmt.Println("Deployment process initialized.") - + color.Set(color.FgGreen) + fmt.Println("Deployment Done.") + color.Unset() + color.Set(color.FgYellow) + fmt.Println("Thank you for using Harness CLI.") + color.Unset() return nil } @@ -143,7 +149,7 @@ func promptUser(prompt, defaultValue string) string { func loadProjectInfo() (string, string, error) { file, err := os.Open(defaults.TEMPFILEPATH) if err != nil { - return "", "", fmt.Errorf("failed to open temp file: %v", err) + return "", "", fmt.Errorf("please run 'harness init' first") } defer file.Close() @@ -256,3 +262,16 @@ func saveDockerfileInfo(hasDockerfile bool) error { return nil } + +func ProjectprogressBar(info string) { + barLength := 20 + spinChars := []string{"|", "/", "-", "\\"} + for i := 0; i <= barLength; i++ { + spinner := spinChars[i%len(spinChars)] + progress := strings.Repeat("=", i) + strings.Repeat(" ", barLength-i) + color.Set(color.FgCyan) + fmt.Printf("\r[%s] %s %s", progress, spinner, info) + color.Unset() + time.Sleep(time.Millisecond * 100) + } +} diff --git a/init.go b/init.go index 9bf84a8..6dcf7a6 100644 --- a/init.go +++ b/init.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/fatih/color" "os" + "os/exec" "strings" "time" @@ -53,6 +54,19 @@ func InitProject(c *cli.Context) error { fmt.Println("\nHarness project initialized successfully!") color.Unset() + fmt.Print("Do you want to Proceed with the deployment? (y/n) : ") + var deployment string + _, err = fmt.Scanln(&deployment) + if err != nil { + return err + } + if deployment == "y" { + err := deployPipeline() + if err != nil { + return err + } + } + return nil } @@ -115,3 +129,14 @@ func saveProjectInfo(framework, language string) error { return nil } + +func deployPipeline() error { + cmd := exec.Command("harness", "deploy") + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + err := cmd.Run() + if err != nil { + return fmt.Errorf("error running deploy command: %v", err) + } + return nil +} diff --git a/utils/org.go b/utils/org.go index 5ce7c92..2da26b4 100644 --- a/utils/org.go +++ b/utils/org.go @@ -59,7 +59,7 @@ func CheckOrgExistsAndCreate(c *cli.Context, orgName string) (bool, error) { org := getOrganisations(c) orgId := findOrgIdByName(org, orgName) if len(orgId) == 0 { - fmt.Printf("Organization '%s' does not exist. Do you want to create it? (y/n): ", orgName) + fmt.Printf("\nOrganization '%s' does not exist. Do you want to create it? (y/n): ", orgName) var createOrg string fmt.Scanln(&createOrg) @@ -72,7 +72,7 @@ func CheckOrgExistsAndCreate(c *cli.Context, orgName string) (bool, error) { return false, err } } else { - fmt.Printf("Organization '%s' already exists. Do you want to use it? (y/n): ", orgName) + fmt.Printf("\nOrganization '%s' already exists. Do you want to use it? (y/n): ", orgName) var useOrg string fmt.Scanln(&useOrg) diff --git a/utils/pipelines.go b/utils/pipelines.go index 22e978e..22df934 100644 --- a/utils/pipelines.go +++ b/utils/pipelines.go @@ -10,6 +10,8 @@ import ( "net/http" "os" _ "os" + "strings" + "time" ) type Pipeline struct { @@ -104,8 +106,10 @@ func CreatePipeline() { fmt.Printf("Error creating pipeline in Harness: %v\n", err) return } + fmt.Println() + PipelineprogressBar("Creating pipeline in Harness...") color.Set(color.FgGreen) - fmt.Println("Pipeline created successfully!") + fmt.Println("\nPipeline created successfully!") color.Unset() PipelineUrl := "https://app.harness.io/ng/account/" + globals.AccountId + "/home/orgs/" + globals.OrgId + "/projects/" + globals.ProjectId + "/pipelines/" + pipeline.Pipeline.Identifier + "/pipeline-studio/" fmt.Printf("Pipeline Url : %s\n", GetColoredText(PipelineUrl, color.FgCyan)) @@ -148,3 +152,16 @@ func CreateHarnessPipeline(pipelineYAML []byte) error { } return nil } + +func PipelineprogressBar(info string) { + barLength := 20 + spinChars := []string{"|", "/", "-", "\\"} + for i := 0; i <= barLength; i++ { + spinner := spinChars[i%len(spinChars)] + progress := strings.Repeat("=", i) + strings.Repeat(" ", barLength-i) + color.Set(color.FgCyan) + fmt.Printf("\r[%s] %s %s", progress, spinner, info) + color.Unset() + time.Sleep(time.Millisecond * 100) + } +} diff --git a/utils/project.go b/utils/project.go index bf8e3db..0e421a8 100644 --- a/utils/project.go +++ b/utils/project.go @@ -47,7 +47,7 @@ func CheckProjectExistsAndCreate(c *cli.Context, orgName string, projectName str projectId := getProjectIdByName(projects, projectName) if len(projectId) == 0 { - fmt.Println("Project not found. Creating project...") + fmt.Println("\nProject not found. Creating project...") url := fmt.Sprintf("%s/projects?accountIdentifier=%s&orgIdentifier=%s", GetNGBaseURL(c), globals.AccountId, orgName) resp, err := netclient.PostNew(url, globals.ApiKey, ProjectBody{ Project: ProjectDetails{ @@ -63,7 +63,7 @@ func CheckProjectExistsAndCreate(c *cli.Context, orgName string, projectName str } log.Info("Project created successfully") } else { - fmt.Printf("Project '%s' already exists. Do you want to use it? (y/n): ", projectName) + fmt.Printf("\nProject '%s' already exists. Do you want to use it? (y/n): ", projectName) var useProject string fmt.Scanln(&useProject)