菜单和子菜单

时间:2017-10-10 17:42:04

标签: powershell loops menu submenu

主菜单:

1 Delete
2 Create
3 Modify
4 Remove
X Exit

子菜单1(删除):

1 Delete file
2 Delete folder
3 Delete another file
4 Delete another folder
5 Back to Main Menu

子菜单2(用于创建):

1 Create Virtual
2 Create another Virtual
3 Back to Main Menu

子菜单3(用于修改):

1 Modify Virtual
2 Modify another Virtual
3 Back to Main Menu

这是主菜单:

$q = Read-Host "
Please select an option:
1 Delete Files 
2 Create New Virtual
3 Modify Existing Virtual
"

子菜单1

$su1 = Read-Host "
Please select an option
1 Delete a file
2 Delete a folder
3 Delete another file
4 Delete another folder
5 Back to main menu
"

如何选择选项5并将其带回主菜单?

1 个答案:

答案 0 :(得分:1)

您可以为通过交换机的每个菜单创建功能,以便您可以继续调用新菜单

function mainMenu(){
    clear
    switch(Read-Host "1 Delete
2 Create
3 Modify
4 Remove
X Exit"){
        X {break}
        2 {createMenu}
        default {"N/A"}
    }
}

function createMenu(){
    clear
    switch(Read-Host "Please select an option `
1 Delete a file
2 Delete a folder
3 Delete another file
4 Delete another folder
5 Back to main menu"){
        5 {mainMenu}
        default {"N/A"}
    }
}

mainMenu