zoukankan      html  css  js  c++  java
  • Use windows batch script to create menu

    Background

    Recently, I find that we need  to  type some very long gradle commands to run build, check, test, etc. It's very annoying, isn't it?

    Idea

    Can I write a script to run the gradle commands? Is that easy? If so, I only need to type 2 or 3 charactors(like "go" or "go 1") in this way. Considering we are working with windows 7, so I choose windows batch script to make my dream come true. ^_^ 

    Solution

      Step 1: display a menu in the command line

     1 @echo off
     2 ::file name: go.bat
     3 ::##################Menu##################
     4 :menuLoop
     5 echo     Task List
     6 echo 1   Local build (clean build)
     7 echo 2   Quick check (clean check -x :integrationTest ...)
     8 echo 3   Intellij config (--refresh-dependencies cleanIdea idea)
     9 set choice=
    10 echo.&set /p choice=Choose one task or hit ENTER to quit: ||(goto :EOF)
    11 echo.&call :task_%choice%
    12 goto :EOF
    13 
    14 ::##################Tasks##################
    15 :task_1
    16 call gradle clean build
    17 goto :EOF
    18 
    19 :task_2
    20 call gradle clean check -x :integrationTest -x :coberturaIntegrationTest
    21 goto :EOF
    22 
    23 :task_3
    24 call gradle --refresh-dependencies cleanIdea idea
    25 goto :EOF

      Step 2: accept one parameters

    1 ::#################Accept Parameters#################
    2 ::set option=%1
    3 if "%1" == "" (
    4     goto :menuLoop   
    5 ) else (
    6     goto :task_%1
    7 )

      Put this part before the menu codes, then it should work.

    OK, now I only need to type "go 2" if I want to do a quick check on my project codes.

    NOTE: some tasks in the batch script above were written based on our project requirements. You need to make some changes about the commands.

  • 相关阅读:
    Python生成器
    Python迭代器
    模块
    列表推倒式
    内置函数 lambda表达式
    函数
    global、nonlocal、迭代器
    练习
    编码数组字典
    字典
  • 原文地址:https://www.cnblogs.com/penghongwei/p/3289505.html
Copyright © 2011-2022 走看看