浏览代码

args check could accept partly done args

TooManySugar 3 年之前
父节点
当前提交
79f783945e
共有 2 个文件被更改,包括 26 次插入19 次删除
  1. 1 1
      README.md
  2. 25 18
      main.go

+ 1 - 1
README.md

@@ -35,7 +35,7 @@
    - [x] UpdateData.cs - Fully ported needs testing
    - [x] UpdateData.cs - Fully ported needs testing
 
 
 
 
-## Usadge
+## Usage
 	
 	
   As for now where are no releases for GoEthemineTelegramBot, so to run it you need to compile it by yourself. It's easy you will see.
   As for now where are no releases for GoEthemineTelegramBot, so to run it you need to compile it by yourself. It's easy you will see.
   
   

+ 25 - 18
main.go

@@ -36,24 +36,31 @@ func main() {
 	}
 	}
 	myBotClient = *botClient
 	myBotClient = *botClient
 	var me = botClient.Self
 	var me = botClient.Self
-	LogInfo.Printf("Hello, World! I am user %d and my name is %s.\n", me.ID, me.FirstName)
-
-	if len(os.Args[1:]) >= 2 {
-		appSettings.DbUser = os.Args[1]
-		appSettings.DbPassword = os.Args[2]
-	} else {
-		fmt.Print("DataBase Username:")
-		_, err := fmt.Scanln(&appSettings.DbUser)
-		if err != nil {
-			LogError.Panic(os.Stderr, err)
-			return
-		}
-		fmt.Print("DataBase Password:")
-		_, err = fmt.Scanln(&appSettings.DbPassword)
-		if err != nil {
-			LogError.Panic(os.Stderr, err)
-			return
-		}
+	LogInfo.Printf("Hello, World! I am user %d and my name is %s.\n",
+		me.ID, me.FirstName)
+
+	switch len(os.Args[1:]){
+		case 0:
+			fmt.Print("DataBase Username:")
+			_, err := fmt.Scanln(&appSettings.DbUser)
+			if err != nil {
+				LogError.Panic(os.Stderr, err)
+				return
+			}
+		case 1:
+			fmt.Print("DataBase Password:")
+
+			_, err = fmt.Scanln(&appSettings.DbPassword)
+			if err != nil {
+				LogError.Panic(os.Stderr, err)
+				return
+			}
+			break
+
+		default:
+			appSettings.DbUser = os.Args[1]
+			appSettings.DbPassword = os.Args[2]
+			break
 	}
 	}
 
 
 	dBConnector.Init()
 	dBConnector.Init()