Skip to content

Commit c3a2c5c

Browse files
committed
Fix linter issue
1 parent b25bda9 commit c3a2c5c

File tree

1 file changed

+65
-65
lines changed

1 file changed

+65
-65
lines changed

cf_cli_java_plugin.go

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ type JavaPlugin struct {
3232
verbose bool
3333
}
3434

35-
// logVerbose logs a message with a format string if verbose mode is enabled
36-
func (c *JavaPlugin) logVerbose(format string, args ...any) {
35+
// logVerbosef logs a message with a format string if verbose mode is enabled
36+
func (c *JavaPlugin) logVerbosef(format string, args ...any) {
3737
if c.verbose {
3838
fmt.Printf("[VERBOSE] "+format+"\n", args...)
3939
}
@@ -225,22 +225,22 @@ func (c *JavaPlugin) Run(cliConnection plugin.CliConnection, args []string) {
225225
}
226226
}
227227

228-
c.logVerbose("Run called with args: %v", args)
228+
c.logVerbosef("Run called with args: %v", args)
229229

230230
_, err := c.DoRun(cliConnection, args)
231231
if err != nil {
232-
c.logVerbose("Error occurred: %v", err)
232+
c.logVerbosef("Error occurred: %v", err)
233233
os.Exit(1)
234234
}
235-
c.logVerbose("Run completed successfully")
235+
c.logVerbosef("Run completed successfully")
236236
}
237237

238238
// DoRun is an internal method used to wrap the cmd package with CommandExecutor for test purposes
239239
func (c *JavaPlugin) DoRun(cliConnection plugin.CliConnection, args []string) (string, error) {
240240
traceLogger := trace.NewLogger(os.Stdout, true, os.Getenv("CF_TRACE"), "")
241241
ui := terminal.NewUI(os.Stdin, os.Stdout, terminal.NewTeePrinter(os.Stdout), traceLogger)
242242

243-
c.logVerbose("DoRun called with args: %v", args)
243+
c.logVerbosef("DoRun called with args: %v", args)
244244

245245
output, err := c.execute(cliConnection, args)
246246
if err != nil {
@@ -622,15 +622,15 @@ func (c *JavaPlugin) execute(cliConnection plugin.CliConnection, args []string)
622622

623623
fileFlags := []string{"container-dir", "local-dir", "keep", "no-download"}
624624

625-
c.logVerbose("Starting command execution")
626-
c.logVerbose("Command arguments: %v", args)
625+
c.logVerbosef("Starting command execution")
626+
c.logVerbosef("Command arguments: %v", args)
627627

628628
noDownload := options.NoDownload
629629
keepAfterDownload := options.Keep || noDownload
630630

631-
c.logVerbose("Application instance: %d", options.AppInstanceIndex)
632-
c.logVerbose("No download: %t", noDownload)
633-
c.logVerbose("Keep after download: %t", keepAfterDownload)
631+
c.logVerbosef("Application instance: %d", options.AppInstanceIndex)
632+
c.logVerbosef("No download: %t", noDownload)
633+
c.logVerbosef("Keep after download: %t", keepAfterDownload)
634634

635635
remoteDir := options.ContainerDir
636636
// strip trailing slashes from remoteDir
@@ -640,8 +640,8 @@ func (c *JavaPlugin) execute(cliConnection plugin.CliConnection, args []string)
640640
localDir = "."
641641
}
642642

643-
c.logVerbose("Remote directory: %s", remoteDir)
644-
c.logVerbose("Local directory: %s", localDir)
643+
c.logVerbosef("Remote directory: %s", remoteDir)
644+
c.logVerbosef("Local directory: %s", localDir)
645645

646646
argumentLen := len(arguments)
647647

@@ -650,7 +650,7 @@ func (c *JavaPlugin) execute(cliConnection plugin.CliConnection, args []string)
650650
}
651651

652652
commandName := arguments[0]
653-
c.logVerbose("Command name: %s", commandName)
653+
c.logVerbosef("Command name: %s", commandName)
654654

655655
index := -1
656656
for i, command := range commands {
@@ -669,15 +669,15 @@ func (c *JavaPlugin) execute(cliConnection plugin.CliConnection, args []string)
669669
}
670670

671671
command := commands[index]
672-
c.logVerbose("Found command: %s - %s", command.Name, command.Description)
672+
c.logVerbosef("Found command: %s - %s", command.Name, command.Description)
673673
if !command.GenerateFiles && !command.GenerateArbitraryFiles {
674-
c.logVerbose("Command does not generate files, checking for invalid file flags")
674+
c.logVerbosef("Command does not generate files, checking for invalid file flags")
675675
for _, flag := range fileFlags {
676676
if (flag == "container-dir" && options.ContainerDir != "") ||
677677
(flag == "local-dir" && options.LocalDir != "") ||
678678
(flag == "keep" && options.Keep) ||
679679
(flag == "no-download" && options.NoDownload) {
680-
c.logVerbose("Invalid flag %q detected for command %s", flag, command.Name)
680+
c.logVerbosef("Invalid flag %q detected for command %s", flag, command.Name)
681681
return "", &InvalidUsageError{message: fmt.Sprintf("The flag %q is not supported for %s", flag, command.Name)}
682682
}
683683
}
@@ -686,16 +686,16 @@ func (c *JavaPlugin) execute(cliConnection plugin.CliConnection, args []string)
686686
trimmedMiscArgs := strings.TrimLeft(options.Args, " ")
687687
if len(trimmedMiscArgs) > 6 && trimmedMiscArgs[:6] == "start " {
688688
noDownload = true
689-
c.logVerbose("asprof start command detected, setting noDownload to true")
689+
c.logVerbosef("asprof start command detected, setting noDownload to true")
690690
} else {
691691
noDownload = trimmedMiscArgs == "start"
692692
if noDownload {
693-
c.logVerbose("asprof start command detected, setting noDownload to true")
693+
c.logVerbosef("asprof start command detected, setting noDownload to true")
694694
}
695695
}
696696
}
697697
if !command.HasMiscArgs() && options.Args != "" {
698-
c.logVerbose("Command %s does not support --args flag", command.Name)
698+
c.logVerbosef("Command %s does not support --args flag", command.Name)
699699
return "", &InvalidUsageError{message: fmt.Sprintf("The flag %q is not supported for %s", "args", command.Name)}
700700
}
701701
if argumentLen == 1 {
@@ -705,7 +705,7 @@ func (c *JavaPlugin) execute(cliConnection plugin.CliConnection, args []string)
705705
}
706706

707707
applicationName := arguments[1]
708-
c.logVerbose("Application name: %s", applicationName)
708+
c.logVerbosef("Application name: %s", applicationName)
709709

710710
cfSSHArguments := []string{"ssh", applicationName}
711711
if options.AppInstanceIndex > 0 {
@@ -716,32 +716,32 @@ func (c *JavaPlugin) execute(cliConnection plugin.CliConnection, args []string)
716716
return "", &InvalidUsageError{message: fmt.Sprintf("Invalid application instance index %d, must be >= 0", options.AppInstanceIndex)}
717717
}
718718

719-
c.logVerbose("CF SSH arguments: %v", cfSSHArguments)
719+
c.logVerbosef("CF SSH arguments: %v", cfSSHArguments)
720720

721721
supported, err := utils.CheckRequiredTools(applicationName)
722722

723723
if err != nil || !supported {
724724
return "required tools checking failed", err
725725
}
726726

727-
c.logVerbose("Required tools check passed")
727+
c.logVerbosef("Required tools check passed")
728728

729729
remoteCommandTokens := []string{JavaDetectionCommand}
730730

731-
c.logVerbose("Building remote command tokens")
732-
c.logVerbose("Java detection command: %s", JavaDetectionCommand)
731+
c.logVerbosef("Building remote command tokens")
732+
c.logVerbosef("Java detection command: %s", JavaDetectionCommand)
733733

734734
for _, requiredTool := range command.RequiredTools {
735-
c.logVerbose("Setting up required tool: %s", requiredTool)
735+
c.logVerbosef("Setting up required tool: %s", requiredTool)
736736
uppercase := strings.ToUpper(requiredTool)
737737
toolCommand := fmt.Sprintf(`%[1]s_TOOL_PATH=$(find -executable -name %[2]s | head -1 | tr -d [:space:]); if [ -z "$%[1]s_TOOL_PATH" ]; then echo "%[2]s not found"; exit 1; fi; %[1]s_COMMAND=$(realpath "$%[1]s_TOOL_PATH")`, uppercase, requiredTool)
738738
if requiredTool == "jcmd" {
739739
// add code that first checks whether asprof is present and if so use `asprof jcmd` instead of `jcmd`
740740
remoteCommandTokens = append(remoteCommandTokens, toolCommand, "ASPROF_COMMAND=$(realpath $(find -executable -name asprof | head -1 | tr -d [:space:])); if [ -n \"${ASPROF_COMMAND}\" ]; then JCMD_COMMAND=\"${ASPROF_COMMAND} jcmd\"; fi")
741-
c.logVerbose("Added jcmd with asprof fallback")
741+
c.logVerbosef("Added jcmd with asprof fallback")
742742
} else {
743743
remoteCommandTokens = append(remoteCommandTokens, toolCommand)
744-
c.logVerbose("Added tool command for %s", requiredTool)
744+
c.logVerbosef("Added tool command for %s", requiredTool)
745745
}
746746
}
747747
fileName := ""
@@ -750,25 +750,25 @@ func (c *JavaPlugin) execute(cliConnection plugin.CliConnection, args []string)
750750

751751
// Initialize fspath and fileName for commands that need them
752752
if command.GenerateFiles || command.NeedsFileName || command.GenerateArbitraryFiles {
753-
c.logVerbose("Command requires file generation")
753+
c.logVerbosef("Command requires file generation")
754754
fspath, err = utils.GetAvailablePath(applicationName, remoteDir)
755755
if err != nil {
756756
return "", fmt.Errorf("failed to get available path: %w", err)
757757
}
758758
if fspath == "" {
759759
return "", fmt.Errorf("no available path found for file generation")
760760
}
761-
c.logVerbose("Available path: %s", fspath)
761+
c.logVerbosef("Available path: %s", fspath)
762762

763763
if command.GenerateArbitraryFiles {
764764
fspath = fspath + "/" + command.GenerateArbitraryFilesFolderName
765-
c.logVerbose("Updated path for arbitrary files: %s", fspath)
765+
c.logVerbosef("Updated path for arbitrary files: %s", fspath)
766766
}
767767

768768
fileName = fspath + "/" + applicationName + "-" + command.FileNamePart + "-" + utils.GenerateUUID() + command.FileExtension
769769
staticFileName = fspath + "/" + applicationName + command.FileNamePart + command.FileExtension
770-
c.logVerbose("Generated filename: %s", fileName)
771-
c.logVerbose("Generated static filename without UUID: %s", staticFileName)
770+
c.logVerbosef("Generated filename: %s", fileName)
771+
c.logVerbosef("Generated static filename without UUID: %s", staticFileName)
772772
}
773773

774774
commandText := command.SSHCommand
@@ -782,21 +782,21 @@ func (c *JavaPlugin) execute(cliConnection plugin.CliConnection, args []string)
782782
// For arbitrary files commands, insert mkdir and cd before the main command
783783
if command.GenerateArbitraryFiles {
784784
remoteCommandTokens = append(remoteCommandTokens, "mkdir -p "+fspath, "cd "+fspath, commandText)
785-
c.logVerbose("Added directory creation and navigation before command execution")
785+
c.logVerbosef("Added directory creation and navigation before command execution")
786786
} else {
787787
remoteCommandTokens = append(remoteCommandTokens, commandText)
788788
}
789789

790-
c.logVerbose("Command text after replacements: %s", commandText)
791-
c.logVerbose("Full remote command tokens: %v", remoteCommandTokens)
790+
c.logVerbosef("Command text after replacements: %s", commandText)
791+
c.logVerbosef("Full remote command tokens: %v", remoteCommandTokens)
792792

793793
cfSSHArguments = append(cfSSHArguments, "--command")
794794
remoteCommand := strings.Join(remoteCommandTokens, "; ")
795795

796-
c.logVerbose("Final remote command: %s", remoteCommand)
796+
c.logVerbosef("Final remote command: %s", remoteCommand)
797797

798798
if options.DryRun {
799-
c.logVerbose("Dry-run mode enabled, returning command without execution")
799+
c.logVerbosef("Dry-run mode enabled, returning command without execution")
800800
// When printing out the entire command line for separate execution, we wrap the remote command in single quotes
801801
// to prevent the shell processing it from running it in local
802802
cfSSHArguments = append(cfSSHArguments, "'"+remoteCommand+"'")
@@ -805,7 +805,7 @@ func (c *JavaPlugin) execute(cliConnection plugin.CliConnection, args []string)
805805

806806
fullCommand := append([]string{}, cfSSHArguments...)
807807
fullCommand = append(fullCommand, remoteCommand)
808-
c.logVerbose("Executing command: %v", fullCommand)
808+
c.logVerbosef("Executing command: %v", fullCommand)
809809

810810
output, err := cliConnection.CliCommand(fullCommand...)
811811
if err != nil {
@@ -819,26 +819,26 @@ func (c *JavaPlugin) execute(cliConnection plugin.CliConnection, args []string)
819819
}
820820

821821
if command.GenerateFiles {
822-
c.logVerbose("Processing file generation and download")
822+
c.logVerbosef("Processing file generation and download")
823823

824824
var finalFile string
825825
var err error
826826
switch command.FileExtension {
827827
case ".hprof":
828-
c.logVerbose("Finding heap dump file")
828+
c.logVerbosef("Finding heap dump file")
829829
finalFile, err = utils.FindHeapDumpFile(cfSSHArguments, fileName, fspath)
830830
case ".jfr":
831-
c.logVerbose("Finding JFR file")
831+
c.logVerbosef("Finding JFR file")
832832
finalFile, err = utils.FindJFRFile(cfSSHArguments, fileName, fspath)
833833
default:
834834
return "", &InvalidUsageError{message: fmt.Sprintf("Unsupported file extension %q", command.FileExtension)}
835835
}
836836
if err == nil && finalFile != "" {
837837
fileName = finalFile
838-
c.logVerbose("Found file: %s", finalFile)
838+
c.logVerbosef("Found file: %s", finalFile)
839839
fmt.Println("Successfully created " + command.FileLabel + " in application container at: " + fileName)
840840
} else if !noDownload {
841-
c.logVerbose("Failed to find file, error: %v", err)
841+
c.logVerbosef("Failed to find file, error: %v", err)
842842
fmt.Println("Failed to find " + command.FileLabel + " in application container")
843843
return "", err
844844
}
@@ -849,74 +849,74 @@ func (c *JavaPlugin) execute(cliConnection plugin.CliConnection, args []string)
849849
}
850850

851851
localFileFullPath := localDir + "/" + applicationName + "-" + command.FileNamePart + "-" + utils.GenerateUUID() + command.FileExtension
852-
c.logVerbose("Downloading file to: %s", localFileFullPath)
852+
c.logVerbosef("Downloading file to: %s", localFileFullPath)
853853
err = utils.CopyOverCat(cfSSHArguments, fileName, localFileFullPath)
854854
if err == nil {
855-
c.logVerbose("File download completed successfully")
855+
c.logVerbosef("File download completed successfully")
856856
fmt.Println(utils.ToSentenceCase(command.FileLabel) + " file saved to: " + localFileFullPath)
857857
} else {
858-
c.logVerbose("File download failed: %v", err)
858+
c.logVerbosef("File download failed: %v", err)
859859
return "", err
860860
}
861861

862862
if !keepAfterDownload {
863-
c.logVerbose("Deleting remote file")
863+
c.logVerbosef("Deleting remote file")
864864
err = utils.DeleteRemoteFile(cfSSHArguments, fileName)
865865
if err != nil {
866-
c.logVerbose("Failed to delete remote file: %v", err)
866+
c.logVerbosef("Failed to delete remote file: %v", err)
867867
return "", err
868868
}
869-
c.logVerbose("Remote file deleted successfully")
869+
c.logVerbosef("Remote file deleted successfully")
870870
fmt.Println(utils.ToSentenceCase(command.FileLabel) + " file deleted in application container")
871871
} else {
872-
c.logVerbose("Keeping remote file as requested")
872+
c.logVerbosef("Keeping remote file as requested")
873873
}
874874
}
875875
if command.GenerateArbitraryFiles && !noDownload {
876-
c.logVerbose("Processing arbitrary files download: %s", fspath)
877-
c.logVerbose("cfSSHArguments: %v", cfSSHArguments)
876+
c.logVerbosef("Processing arbitrary files download: %s", fspath)
877+
c.logVerbosef("cfSSHArguments: %v", cfSSHArguments)
878878
// download all files in the generic folder
879879
files, err := utils.ListFiles(cfSSHArguments, fspath)
880880
for i, file := range files {
881-
c.logVerbose("File %d: %s", i+1, file)
881+
c.logVerbosef("File %d: %s", i+1, file)
882882
}
883883
if err != nil {
884-
c.logVerbose("Failed to list files: %v", err)
884+
c.logVerbosef("Failed to list files: %v", err)
885885
return "", err
886886
}
887-
c.logVerbose("Found %d files to download", len(files))
887+
c.logVerbosef("Found %d files to download", len(files))
888888
if len(files) != 0 {
889889
for _, file := range files {
890-
c.logVerbose("Downloading file: %s", file)
890+
c.logVerbosef("Downloading file: %s", file)
891891
localFileFullPath := localDir + "/" + file
892892
err = utils.CopyOverCat(cfSSHArguments, fspath+"/"+file, localFileFullPath)
893893
if err == nil {
894-
c.logVerbose("File %s downloaded successfully", file)
894+
c.logVerbosef("File %s downloaded successfully", file)
895895
fmt.Printf("File %s saved to: %s\n", file, localFileFullPath)
896896
} else {
897-
c.logVerbose("Failed to download file %s: %v", file, err)
897+
c.logVerbosef("Failed to download file %s: %v", file, err)
898898
return "", err
899899
}
900900
}
901901

902902
if !keepAfterDownload {
903-
c.logVerbose("Deleting remote file folder")
903+
c.logVerbosef("Deleting remote file folder")
904904
err = utils.DeleteRemoteFile(cfSSHArguments, fspath)
905905
if err != nil {
906-
c.logVerbose("Failed to delete remote folder: %v", err)
906+
c.logVerbosef("Failed to delete remote folder: %v", err)
907907
return "", err
908908
}
909-
c.logVerbose("Remote folder deleted successfully")
909+
c.logVerbosef("Remote folder deleted successfully")
910910
fmt.Println("File folder deleted in application container")
911911
} else {
912-
c.logVerbose("Keeping remote files as requested")
912+
c.logVerbosef("Keeping remote files as requested")
913913
}
914914
} else {
915-
c.logVerbose("No files found to download")
915+
c.logVerbosef("No files found to download")
916916
}
917917
}
918918
// We keep this around to make the compiler happy, but commandExecutor.Execute will cause an os.Exit
919-
c.logVerbose("Command execution completed successfully")
919+
c.logVerbosef("Command execution completed successfully")
920920
return strings.Join(output, "\n"), err
921921
}
922922

0 commit comments

Comments
 (0)