Parcourir la source

Improve conversion bash to batch

Pierre-Yves Barriat il y a 2 ans
Parent
commit
c5f30504dd

+ 0 - 34
exercices/_generic_create.bat

@@ -1,34 +0,0 @@
-@echo off
-call:%~1
-goto exit
-
-:_create
-  echo "Removing exercice"
-  DEL /S "repo" "work"
-  echo "creating directories"
-  mkdir "-p" "repo" "work"
-  echo "initializing repository"
-  cd "repo"
-  git "init" "--bare" REM UNKNOWN: {"type":"Redirect","op":{"text":">","type":"great"},"file":{"text":"/dev/null","type":"Word"}}
-  cd "%CD%."
-  echo "cloning repository"
-  cd "work"
-  git "clone" "%CD%.\repo" "%CD%" REM UNKNOWN: {"type":"Redirect","op":{"text":">","type":"great"},"file":{"text":"/dev/null","type":"Word"}} REM UNKNOWN: {"type":"Redirect","op":{"text":">&","type":"greatand"},"file":{"text":"1","type":"Word"},"numberIo":{"text":"2","type":"io_number"}}
-  echo "Initializing exercice"
-  IF "%~2" == "debug" (
-    $1
-  ) ELSE (
-    $1 REM UNKNOWN: {"type":"Redirect","op":{"text":">","type":"great"},"file":{"text":"/dev/null","type":"Word"}} REM UNKNOWN: {"type":"Redirect","op":{"text":">&","type":"greatand"},"file":{"text":"1","type":"Word"},"numberIo":{"text":"2","type":"io_number"}}
-  )
-  cd "%CD%."
-  echo ""
-  echo "Exercice in %undefined%\work\"
-  echo "=========================================="
-  cat "readme.txt"
-  echo "=========================================="
-  echo ""
-goto:eof
-
-:exit
-exit /b 0
-

+ 0 - 33
exercices/_generic_create.sh

@@ -1,33 +0,0 @@
-#!/bin/bash
-
-function _create() {
-    echo "Removing exercice"
-    rm -rf repo work
-    
-    echo "creating directories"
-    mkdir -p repo work
-    
-    echo "initializing repository"
-    cd repo
-    git init --bare > /dev/null
-    cd ..
-    
-    echo "cloning repository"
-    cd work
-    git clone ../repo . > /dev/null 2>&1
-    
-    echo "Initializing exercice"
-    if [ "$2" == "debug" ]; then
-	$1
-    else
-	$1 > /dev/null 2>&1
-    fi
-    
-    cd ..
-    echo ""
-    echo "Exercice in $(pwd)/work/"
-    echo "=========================================="
-    cat readme.txt
-    echo "=========================================="
-    echo ""
-}

+ 3 - 3
exercices/ex.1/README.md

@@ -2,8 +2,8 @@ You have accidentaly put `first.txt` in the **staging area**
 
 While you actually want to only commit `second.txt`.
 
-You need to, from the current state, only commit `second.txt`.
+You need to, from the current state, only commit `second.txt`:
 
-- remove the file `second.txt` (Use `git status` to get the appropriate command)
-- add `first.txt`
+- remove the file `first.txt` (Use `git status` to get the appropriate command)
+- add `second.txt`
 - commit

+ 14 - 5
exercices/ex.1/create.bat

@@ -1,9 +1,18 @@
 @echo off
 
+SET SOME_VAR=.\first.txt
+DEL /S "%SOME_VAR%" || echo "file not found"
+SET SOME_VAR=.\second.txt
+DEL /S "%SOME_VAR%" || echo "file not found"
+CALL :_ex
+
+EXIT /B %ERRORLEVEL%
+
 :_ex
-    echo "un" REM UNKNOWN: {"type":"Redirect","op":{"text":">","type":"great"},"file":{"text":"first.txt","type":"Word"}}
-    echo "deux" REM UNKNOWN: {"type":"Redirect","op":{"text":">","type":"great"},"file":{"text":"second.txt","type":"Word"}}
-    git "add" "first.txt"
-exit /b
+echo "2 files have been created !"
+echo un> first.txt
+echo deux> second.txt
+dir *.txt
+git add first.txt
+EXIT /B 0
 
-call _generic_create.bat _create _ex

+ 3 - 9
exercices/ex.1/create.sh

@@ -1,12 +1,6 @@
 #!/bin/bash
 
-source ../_generic_create.sh
+echo "un" > first.txt
+echo "deux" > second.txt
 
-function _ex() {
-    echo "un" > first.txt
-    echo "deux" > second.txt
-
-    git add first.txt
-}
-
-_create _ex
+git add first.txt

+ 20 - 0
exercices/ex.2/create.bat

@@ -0,0 +1,20 @@
+@echo off
+
+SET SOME_VAR="main.cpp"
+DEL /S "%SOME_VAR%" || echo "file not found"
+SET SOME_VAR="main.cpp~"
+DEL /S "%SOME_VAR%" || echo "file not found"
+SET SOME_VAR=out
+DEL /S "%SOME_VAR%" || echo "file not found"
+CALL :_ex
+
+EXIT /B %ERRORLEVEL%
+
+:_ex
+touch "main.cpp"
+touch "main.cpp~"
+mkdir "-p" "out"
+touch "out\main.o"
+touch "out\a.out"
+touch "out\conf.ini"
+EXIT /B 0

+ 8 - 14
exercices/ex.2/create.sh

@@ -1,16 +1,10 @@
 #!/bin/bash
 
-source ../_generic_create.sh
-
-function _ex() {
-    touch main.cpp
-    touch main.cpp~
-
-    mkdir -p out
-    touch out/main.o
-    touch out/a.out
-    touch out/conf.ini
-}
-
-_create _ex
-
+touch main.cpp
+touch main.cpp~
+
+mkdir -p out
+touch out/main.o
+touch out/a.out
+touch out/conf.ini
+