Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding markdown part #141

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
66 changes: 44 additions & 22 deletions dop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ EXIT_ENV=3
EXIT_CONFIG=4

usage() {
echo "Usage: dop [-c CONFIG] [-v] [-h] [-r DIR] [-t <json|plain>] [-l] ROOT" >&2
echo "Usage: dop [-c CONFIG] [-v] [-h] [-r DIR] [-t <json|plain>] [-g <md|html>] [-l] ROOT" >&2
balat marked this conversation as resolved.
Show resolved Hide resolved
[ -z $1 ] && exit $EXIT_USAGE || exit $1
}

Expand Down Expand Up @@ -48,13 +48,33 @@ find_ohow() {
}

process_options() {
[ $format = plain -o $format = json ] || usage
if [ $format = json ]; then
check_jq
json=true
else
json=false
fi
case $config_format in
json)
check_jq
json=true
;;
plain)
json=false
;;
*)
echo "Unsupported configuration format specified with -t option: $config_format" >&2
usage $EXIT_USAGE
;;
esac

case $output_language in
md|markdown)
output_language=md
;;
html)
output_language=html
;;
*)
echo "Unsupported output language specified with -g option: $output_language" >&2
usage $EXIT_USAGE
;;
esac

[ -d $wikidir ] || {
echo "Wiki directory $wikidir does not exist. Aborting." >&2
exit $EXIT_CONFIG
Expand All @@ -67,7 +87,6 @@ process_options() {
fi
}


first_that_exists() {
local tst=$1
shift
Expand Down Expand Up @@ -107,13 +126,13 @@ infer_config() {
project=$(basename `pwd`)
default_subp=

man=$(first_that_exists -d manual manual_wiki manual_wikis man)
manual=$(first_that_exists -d manual manual_wiki manual_wikis man)
api=$(first_that_exists -d api api_wiki api_wikis apis)
assets=$(first_that_exists -d assets files $man/assets $man/files)
images=$(first_that_exists -d images files illustrations $man/assets $man/files $man/illustrations)
assets=$(first_that_exists -d assets files $manual/assets $manual/files)
images=$(first_that_exists -d images files illustrations $manual/assets $manual/files $manual/illustrations)
[ -z "$images" -a -n "$assets" ] && images=$assets
[ -z "$assets" -a -n "$images" ] && assets=$images
contains_wikis $man || man=$(first_that_exists -d $man/src $man/wiki $man/wikis $man)
contains_wikis $manual || man=$(first_that_exists -d $manual/src $manual/wiki $manual/wikis $manual)

client=$(first_that_exists -d $api/client)
server=$(first_that_exists -d $api/server)
Expand Down Expand Up @@ -216,7 +235,7 @@ show_config() {
if $json; then
jq . <<EOF
{"project": "$project",
"manual": "$man", "api": "$api",
"manual": "$manual", "api": "$api",
"assets": "$assets", "images": "$images",
"default_subproject": $dsp,
"client": "$client", "server": "$server",
Expand All @@ -226,7 +245,7 @@ show_config() {
EOF
else
echo "project $project"
echo "manual $man"
echo "manual $manual"
echo "api $api"
echo "assets $assets"
echo "images $images"
Expand All @@ -250,17 +269,18 @@ call_ohow() {
local opts="--root $root"
$is_local && opts="$opts --local"
[ -n "$project" ] && opts="$opts --project $project"
[ -n "$man" ] && opts="$opts --manual $man"
[ -n "$manual" ] && opts="$opts --manual $manual"
[ -n "$api" ] && opts="$opts --api $api"
[ -n "$assets" ] && opts="$opts --assets $assets"
[ -n "$images" ] && opts="$opts --images $images"
[ -n "$default_subp" ] && opts="$opts --default-subproject $default_subp"
[ -n "$docversions" ] && opts="$opts --docversions $docversions"
[ -n "$templates" ] && opts="$opts --template $templates"

if $csw
then $ohow $opts --csw <(csw) $1
else $ohow $opts $1
if $csw; then
$ohow $opts --csw <(csw) $1 --out-language $output_language
else
$ohow $opts $1 --out-language $output_language
fi
}

Expand Down Expand Up @@ -317,19 +337,21 @@ find_ohow
verbose=false
root="_dop"
config=
format=plain
config_format=plain
output_language=html
force=false
is_local=false
keep_wikis=false
show_inferred=false
show_used=false
no_run=false
docversions=
while getopts hr:c:t:vflkiusnd: opt; do
while getopts hr:c:t:g:vflkiusnd: opt; do
case "$opt" in
r) root="$OPTARG";;
c) config="$OPTARG";;
t) format="$OPTARG";;
t) config_format="$OPTARG";;
g) output_language="$OPTARG";;
f) force=true;;
v) verbose=true;;
l) is_local=true;;
Expand Down
9 changes: 7 additions & 2 deletions ohow-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ OPTIONS
Writes the HTML into the given file. Always overwrites. Overrides
--print.

--out-language=LANGUAGE (absent=html)
The output language for the export. Can be 'md' for Markdown or
'html' for HTML.

-p, --print
Print the HTML to stdout.

Expand All @@ -118,7 +122,8 @@ OPTIONS
-r, --hl, --headless
Produces raw HTML without head tag and not inside a body tag.

--root=DIR (absent=/home/hugo/html_of_wiki/_build/default)
--root=DIR
(absent=/home/bibou/Documents/stage/html_of_wiki/_build/default)
Use the given root directory.

-t FILE, --template=FILE
Expand All @@ -134,7 +139,7 @@ COMMON OPTIONS
Show version information.

EXIT STATUS
ohow exits with the following status:
ohow exits with:

0 on success.

Expand Down
15 changes: 13 additions & 2 deletions src/ohow/cli.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
open Import

let out_language_cmd =
let doc =
"The output language for the export. Can be 'md' for Markdown or 'html' \
for HTML."
in
Cmdliner.Arg.(
value & opt string "html" & info [ "out-language" ] ~docv:"LANGUAGE" ~doc)

let file_cmd =
let doc = "A wikicreole file to convert to HTML." in
Cmdliner.Arg.(non_empty & pos_all file [] & info [] ~docv:"FILE" ~doc)
Expand Down Expand Up @@ -158,7 +166,8 @@ let info_cmd =
Cmd.info "ohow" ~version:"v2.0" ~doc ~man)

let register_options k print headless outfile project root manual api
default_subproject images assets template csw docversions local files =
default_subproject images assets template csw docversions local out_language
files =
let open Operators in
let suffix = if local then ".html" else "" in
let pretty = local in
Expand Down Expand Up @@ -188,6 +197,7 @@ let register_options k print headless outfile project root manual api
; csw
; docversions
; local
; out_language
; files
}
in
Expand All @@ -199,7 +209,8 @@ let run main =
const (register_options main)
$ print_cmd $ headless_cmd $ outfile_cmd $ project_cmd $ root_cmd
$ manual_cmd $ api_cmd $ default_subproject_cmd $ img_cmd $ assets_cmd
$ template_cmd $ csw_cmd $ docversions_cmd $ local_cmd $ file_cmd)
$ template_cmd $ csw_cmd $ docversions_cmd $ local_cmd $ out_language_cmd
$ file_cmd)
in
let command = Cmdliner.Cmd.v info_cmd ohow_cmd in
exit Cmdliner.Cmd.(eval command)
12 changes: 7 additions & 5 deletions src/ohow/global.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type cli_options =
; assets : string option
; template : string option
; csw : string list
; out_language : string
; docversions : string list
}

Expand All @@ -84,30 +85,31 @@ let with_options opts k =
let using_options k =
match !ref_options with
| Some options -> k options
| None -> failwith "Global.options isn't properly intialized."
| None ->
failwith (current_file () ^ "Global.options isn't properly intialized.")

let options () = using_options (fun x -> x)
let suffix () = (options ()).suffix

let the_manual () =
match (options ()).manual with
| Some s -> s
| None -> failwith "no manual given"
| None -> failwith ("no manual given" ^ current_file ())

let the_api () =
match (options ()).api with
| Some s -> s
| None -> failwith "no api given"
| None -> failwith ("no api given" ^ current_file ())

let the_images () =
match (options ()).images with
| Some s -> s
| None -> failwith "no images given"
| None -> failwith ("no images given" ^ current_file ())

let the_assets () =
match (options ()).assets with
| Some s -> s
| None -> failwith "no assets given"
| None -> failwith ("no assets given" ^ current_file ())

(* Preserve absolute path *)
let root () = (options ()).root
Expand Down
1 change: 1 addition & 0 deletions src/ohow/global.mli
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type cli_options =
; assets : string option
; template : string option
; csw : string list
; out_language : string
; docversions : string list
}

Expand Down
Loading