Skip to content

Commit

Permalink
Do "press any key to continue" on separate bat
Browse files Browse the repository at this point in the history
The old version of the script only prevented closing the cmd window on
Windos whan a syntax error occurred. If a command line parsing error or
uncaught exceptin occurred it would not pause the program.

The fix for this is to move the "press any key to continue" feature to a
separate windows-only bat file and get rid of the "--quiet" flag. This
also means there is no cruft for the Linux version of the program.
  • Loading branch information
Hugo committed Dec 19, 2014
1 parent 13bb80d commit fea16c6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ All with a familiar and easy to learn syntax. Interested? Lets take a closer loo

##How to use scfg

First of all, go to my [github releases page](https://github.com/hugomg/scfgc/releases) to download the executable for the scfg compiler.
First of all, go to my [github releases page](https://github.com/hugomg/scfgc/releases) to download the executable for the scfg compiler. The zip should include two files, scfg.exe and scfg.bat

In Windows explorer, drag your scfg source file on top of the icon for the scfgc.exe executable.
scfg will convert that scfg file into a cfg file of the same name and place it next to the scfg source file.
If you know how to use the command line you can call scfg.exe directly.
Run `scfgc.exe --help` for usage isntructions.

If you don't know how to use the command line you can use scfgc from Windows Explorer.
First, create a scfg script with the ".scfg" file extension. You can find some example files
[here](https://github.com/hugomg/scfgc/tree/master/examples).
Then, in the Windows Explorer window, drag the icon for the scfg file and drop it on top of the icon for the scfg.bat file. (Droping on top of scfg.exe also works, but won't show any error messages if a problem occurs).
If everything goes right, scfgc should convert your scfg file into a cfg file of the same name and place it next to the scfg source file.
You can then add a line on your autoexec.cfg file to call your script when Dota2 starts up.

For more complex scripts, scfg might not be able to compile your scfg file into a single cfg file.
In these cases, it will also generate a folder with the same base name as your scfg file, containing
helper files for your script.

Alternatively, you can invoke scfgc from the command line. Run `scfgc.exe --help` for usage instructions.

##Commands

A command consists of a command name followed by zero or more arguments. The argument list extends
Expand Down
21 changes: 4 additions & 17 deletions main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ let skip_utf8_BOM chan =
if not (n = bom_len && String.equal bom (Bytes.to_string buf)) then
In_channel.seek chan orig_pos

let compile quiet in_filename =

let compile in_filename =

let exit_with_error errname pos errinfo =
(match pos with
Expand All @@ -41,13 +42,6 @@ let compile quiet in_filename =
| None -> ()
| Some s -> fprintf stderr ": %s" s);
fprintf stderr "\n";
if not quiet then (
(* Windows Explorer closes scfgc's terminal window, hiding errors,
* unless we prompt the user for input. *)
fprintf stderr "Press ENTER to continue:";
Out_channel.flush stderr;
ignore @@ In_channel.input_byte stdin
);
exit 1
in

Expand Down Expand Up @@ -128,11 +122,6 @@ let compile quiet in_filename =
(* ----- *)
open Cmdliner

let quiet =
let doc = "Skip the \"Press any key to continue\" prompt if there is an error. \
Use this option if you are running scfgc from the command line." in
Arg.(value @@ flag @@ info ["q"; "quiet"] ~doc ~docv:"quiet")

let filename =
let doc = "Source .scfg file" in
Arg.(required @@ pos 0 (some @@ file) None @@ info [] ~doc ~docv:"filename")
Expand All @@ -148,12 +137,10 @@ let cmd =
`P "Send bugs and suggestions to https://github.com/hugomg/scfgc";
] in
Term.(
pure compile $ quiet $ filename,
info "scfgc" ~version:"0.2" ~doc ~man)
pure compile $ filename,
info "scfgc" ~version:"0.3" ~doc ~man)

let () =
match Term.eval cmd with
| `Version | `Help | `Ok _ -> exit 0
| `Error _ -> exit 1


3 changes: 3 additions & 0 deletions scfgc.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
scfgc.exe %*
if errorlevel 1 pause

0 comments on commit fea16c6

Please sign in to comment.