Skip to content

Commit 5895b46

Browse files
committed
Improve styling and flow for status / auth
Signed-off-by: Phil Ewels <[email protected]>
1 parent 0c534a1 commit 5895b46

File tree

1 file changed

+83
-35
lines changed

1 file changed

+83
-35
lines changed

modules/nextflow/src/main/groovy/nextflow/cli/CmdAuth.groovy

Lines changed: 83 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ class CmdAuth extends CmdBase implements UsageAware {
782782
// Save updated config only if changes were made
783783
if (configChanged) {
784784
writeConfig(config)
785-
ColorUtil.printColored(" - Configuration saved to ${ColorUtil.colorize(getConfigFile().toString(), 'magenta')}", "green")
785+
ColorUtil.printColored("\nConfiguration saved to ${ColorUtil.colorize(getConfigFile().toString(), 'magenta')}", "green")
786786
}
787787

788788
} catch (Exception e) {
@@ -793,13 +793,12 @@ class CmdAuth extends CmdBase implements UsageAware {
793793
private boolean configureEnabled(Map config) {
794794
def currentEnabled = config.get('tower.enabled', false)
795795

796-
println "Workflow monitoring settings:"
797-
println " Current: ${currentEnabled ? 'enabled' : 'disabled'}"
798-
println " When enabled, all workflow runs are automatically monitored by Seqera Platform"
799-
println " When disabled, you can enable per-run with the -with-tower flag"
796+
println "Workflow monitoring settings. Current setting: ${currentEnabled ? ColorUtil.colorize('enabled', 'green') : ColorUtil.colorize('disabled', 'red')}"
797+
ColorUtil.printColored(" When enabled, all workflow runs are automatically monitored by Seqera Platform", "dim")
798+
ColorUtil.printColored(" When disabled, you can enable per-run with the ${ColorUtil.colorize('-with-tower', 'cyan')} flag", "dim")
800799
println ""
801800

802-
System.out.print("Enable workflow monitoring for all runs? (${currentEnabled ? 'Y/n' : 'y/N'}): ")
801+
System.out.print("${ColorUtil.colorize('Enable workflow monitoring for all runs?', 'cyan bold', true)} (${currentEnabled ? ColorUtil.colorize('Y', 'green') + '/n' : 'y/' + ColorUtil.colorize('N', 'red')}): ")
803802
System.out.flush()
804803

805804
def reader = new BufferedReader(new InputStreamReader(System.in))
@@ -843,17 +842,6 @@ class CmdAuth extends CmdBase implements UsageAware {
843842
def effectiveWorkspaceId = currentWorkspaceId ?: envWorkspaceId
844843
def currentWorkspace = workspaces.find { ((Map)it).workspaceId.toString() == effectiveWorkspaceId?.toString() }
845844

846-
println "Default workspace settings:"
847-
if (currentWorkspace) {
848-
def workspace = currentWorkspace as Map
849-
def source = currentWorkspaceId ? "config" : (envWorkspaceId ? "TOWER_WORKFLOW_ID env var" : "config")
850-
println " Current: ${workspace.orgName} / ${workspace.workspaceName} [${workspace.workspaceFullName}] (from ${source})"
851-
} else if (envWorkspaceId) {
852-
println " Current: TOWER_WORKFLOW_ID=${envWorkspaceId} (workspace not found in available workspaces)"
853-
} else {
854-
println " Current: Personal workspace (default)"
855-
}
856-
println ""
857845

858846
// Group by organization
859847
def orgWorkspaces = workspaces.groupBy { ((Map)it).orgName ?: 'Personal' }
@@ -868,16 +856,29 @@ class CmdAuth extends CmdBase implements UsageAware {
868856
}
869857

870858
private boolean selectWorkspaceFromAll(Map config, List workspaces, def currentWorkspaceId, def envWorkspaceId) {
871-
println "Select default workspace:"
872-
println " 0. Personal workspace (no organization)"
859+
println "\nAvailable workspaces:"
860+
println " 0. ${ColorUtil.colorize('Personal workspace', 'cyan', true)} ${ColorUtil.colorize('[no organization]', 'dim', true)}"
873861

874862
workspaces.eachWithIndex { workspace, index ->
875863
def ws = workspace as Map
876-
def prefix = ws.orgName ? "${ws.orgName} / " : ""
877-
println " ${index + 1}. ${prefix}${ws.workspaceName} [${ws.workspaceFullName}]"
864+
def prefix = ws.orgName ? "${ColorUtil.colorize(ws.orgName as String, 'cyan', true)} / " : ""
865+
println " ${index + 1}. ${prefix}${ColorUtil.colorize(ws.workspaceName as String, 'magenta', true)} ${ColorUtil.colorize('[' + (ws.workspaceFullName as String) + ']', 'dim', true)}"
878866
}
879867

880-
System.out.print("Select workspace (0-${workspaces.size()}, Enter to keep current): ")
868+
// Show current workspace and prepare prompt
869+
def currentWorkspace = workspaces.find { ((Map)it).workspaceId.toString() == (currentWorkspaceId ?: System.getenv('TOWER_WORKFLOW_ID'))?.toString() }
870+
def currentWorkspaceName
871+
if (currentWorkspace) {
872+
def workspace = currentWorkspace as Map
873+
def source = currentWorkspaceId ? "config" : "TOWER_WORKFLOW_ID env var"
874+
currentWorkspaceName = "${workspace.orgName} / ${workspace.workspaceName}"
875+
} else if (System.getenv('TOWER_WORKFLOW_ID')) {
876+
currentWorkspaceName = "TOWER_WORKFLOW_ID=${System.getenv('TOWER_WORKFLOW_ID')}"
877+
} else {
878+
currentWorkspaceName = "Personal workspace"
879+
}
880+
881+
ColorUtil.printColored("\nSelect workspace (0-${workspaces.size()}, press Enter to keep as '${currentWorkspaceName}'): ", "bold cyan")
881882
System.out.flush()
882883

883884
def reader = new BufferedReader(new InputStreamReader(System.in))
@@ -920,15 +921,45 @@ class CmdAuth extends CmdBase implements UsageAware {
920921
}
921922

922923
private boolean selectWorkspaceByOrg(Map config, Map orgWorkspaces, def currentWorkspaceId, def envWorkspaceId) {
924+
// Get current workspace info for prompts
925+
def allWorkspaces = []
926+
orgWorkspaces.values().each { workspaceList ->
927+
allWorkspaces.addAll(workspaceList as List)
928+
}
929+
def currentWorkspace = allWorkspaces.find { ((Map)it).workspaceId.toString() == (currentWorkspaceId ?: envWorkspaceId)?.toString() }
930+
def currentOrgName
931+
def currentWorkspaceName
932+
if (currentWorkspace) {
933+
def workspace = currentWorkspace as Map
934+
currentOrgName = workspace.orgName as String
935+
currentWorkspaceName = workspace.workspaceName as String
936+
} else if (envWorkspaceId) {
937+
currentOrgName = "TOWER_WORKFLOW_ID=${envWorkspaceId}"
938+
currentWorkspaceName = null
939+
} else {
940+
currentOrgName = "Personal"
941+
currentWorkspaceName = null
942+
}
943+
923944
// First, select organization
924945
def orgs = orgWorkspaces.keySet().toList()
925946

926-
println "Select organization:"
927-
orgs.eachWithIndex { orgName, index ->
928-
println " ${index + 1}. ${orgName}"
947+
println "\nAvailable organizations:"
948+
// Add Personal workspace option if not already in the list
949+
def hasPersonal = orgs.contains('Personal')
950+
if (!hasPersonal) {
951+
println " 1. ${ColorUtil.colorize('Personal', 'cyan', true)} ${ColorUtil.colorize('[Personal workspace - no organization]', 'dim', true)}"
952+
orgs.eachWithIndex { orgName, index ->
953+
println " ${index + 2}. ${ColorUtil.colorize(orgName as String, 'cyan', true)}"
954+
}
955+
System.out.print("${ColorUtil.colorize("Select organization (1-${orgs.size() + 1}, Enter to keep as '${currentOrgName}'): ", 'dim', true)}")
956+
} else {
957+
orgs.eachWithIndex { orgName, index ->
958+
def displayName = orgName == 'Personal' ? 'Personal [Personal workspace - no organization]' : orgName
959+
println " ${index + 1}. ${ColorUtil.colorize(displayName as String, 'cyan', true)}"
960+
}
961+
System.out.print("${ColorUtil.colorize("Select organization (1-${orgs.size()}, Enter to keep as '${currentOrgName}'): ", 'dim', true)}")
929962
}
930-
931-
System.out.print("Select organization (1-${orgs.size()}, Enter to keep current): ")
932963
System.out.flush()
933964

934965
def reader = new BufferedReader(new InputStreamReader(System.in))
@@ -940,12 +971,28 @@ class CmdAuth extends CmdBase implements UsageAware {
940971

941972
try {
942973
def orgSelection = Integer.parseInt(orgInput)
943-
if (orgSelection < 1 || orgSelection > orgs.size()) {
974+
def maxOrgSelection = hasPersonal ? orgs.size() : orgs.size() + 1
975+
if (orgSelection < 1 || orgSelection > maxOrgSelection) {
944976
println "Invalid selection."
945977
return false
946978
}
947979

948-
def selectedOrgName = orgs[orgSelection - 1]
980+
def selectedOrgName
981+
if (!hasPersonal && orgSelection == 1) {
982+
// Personal workspace selected
983+
if (envWorkspaceId) {
984+
return false
985+
} else {
986+
def hadWorkspaceId = config.containsKey('tower.workspaceId')
987+
config.remove('tower.workspaceId')
988+
config.remove('tower.workspaceId.comment')
989+
return hadWorkspaceId
990+
}
991+
} else {
992+
def orgIndex = hasPersonal ? orgSelection - 1 : orgSelection - 2
993+
selectedOrgName = orgs[orgIndex]
994+
}
995+
949996
def orgWorkspaceList = orgWorkspaces[selectedOrgName] as List
950997

951998
println ""
@@ -957,11 +1004,12 @@ class CmdAuth extends CmdBase implements UsageAware {
9571004

9581005
orgWorkspaceList.eachWithIndex { workspace, index ->
9591006
def ws = workspace as Map
960-
println " ${index + 1}. ${ws.workspaceName} [${ws.workspaceFullName}]"
1007+
println " ${index + 1}. ${ColorUtil.colorize(ws.workspaceName as String, 'magenta', true)} ${ColorUtil.colorize('[' + (ws.workspaceFullName as String) + ']', 'dim', true)}"
9611008
}
9621009

9631010
def maxSelection = orgWorkspaceList.size()
964-
System.out.print("Select workspace (${selectedOrgName == 'Personal' ? '0-' : '1-'}${maxSelection}, Enter to keep current): ")
1011+
def keepAsText = currentWorkspaceName ? "'${currentWorkspaceName}'" : "'Personal workspace'"
1012+
System.out.print("${ColorUtil.colorize("Select workspace (${selectedOrgName == 'Personal' ? '0-' : '1-'}${maxSelection}, Enter to keep as ${keepAsText}): ", 'dim', true)}")
9651013
System.out.flush()
9661014

9671015
def wsInput = reader.readLine()?.trim()
@@ -1064,7 +1112,7 @@ class CmdAuth extends CmdBase implements UsageAware {
10641112
try {
10651113
def userInfo = callUserInfoApi(tokenInfo.value as String, endpointInfo.value as String)
10661114
def currentUser = userInfo.userName as String
1067-
statusRows.add(['Authentication', "${ColorUtil.colorize('OK', 'green')} ${ColorUtil.colorize('(user: ' + currentUser + ')', 'cyan')}".toString(), tokenInfo.source as String])
1115+
statusRows.add(['Authentication', "${ColorUtil.colorize('OK', 'green')} (user: ${ColorUtil.colorize(currentUser, 'cyan')})".toString(), tokenInfo.source as String])
10681116
} catch (Exception e) {
10691117
statusRows.add(['Authentication', ColorUtil.colorize('ERROR', 'red'), 'failed'])
10701118
}
@@ -1097,10 +1145,10 @@ class CmdAuth extends CmdBase implements UsageAware {
10971145
def truncatedFullName = fullName.length() > 50 ? fullName.substring(0, 47) + '...' : fullName
10981146
statusRows.add([' - workspace full name', ColorUtil.colorize(truncatedFullName, 'cyan dim'), ''])
10991147
} else {
1100-
statusRows.add(['Default workspace', ColorUtil.colorize(workspaceInfo.value as String, 'blue'), workspaceInfo.source as String])
1148+
statusRows.add(['Default workspace', ColorUtil.colorize(workspaceInfo.value as String, 'blue', true), workspaceInfo.source as String])
11011149
}
11021150
} else {
1103-
statusRows.add(['Default workspace', ColorUtil.colorize('Personal workspace', 'cyan'), 'default'])
1151+
statusRows.add(['Default workspace', ColorUtil.colorize('Personal workspace', 'cyan', true), 'default'])
11041152
}
11051153

11061154
// Print table
@@ -1129,7 +1177,7 @@ class CmdAuth extends CmdBase implements UsageAware {
11291177
rows.each { row ->
11301178
def paddedCol1 = padStringWithAnsi(row[0], col1Width)
11311179
def paddedCol2 = padStringWithAnsi(row[1], col2Width)
1132-
def paddedCol3 = ColorUtil.colorize(row[2], 'dim')
1180+
def paddedCol3 = ColorUtil.colorize(row[2], 'dim', true)
11331181
println "${paddedCol1} ${paddedCol2} ${paddedCol3}"
11341182
}
11351183
}

0 commit comments

Comments
 (0)