Skip to content

Commit

Permalink
Merge pull request #4129 from OCamlPro/5008bfb
Browse files Browse the repository at this point in the history
Revert "Add missing Cmdliner.Manpage.escape calls"
  • Loading branch information
AltGr authored Apr 16, 2020
2 parents 81cc31b + dd54bca commit 8520b17
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
17 changes: 10 additions & 7 deletions src/client/opamAdminCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let checked_repo_root () =
then
OpamConsole.error_and_exit `Bad_arguments
"No repository found in current directory.\n\
Please make sure there is a \"packages%s\" directory" Filename.dir_sep;
Please make sure there is a \"packages%s\" directory" OpamArg.dir_sep;
repo_root


Expand All @@ -36,7 +36,7 @@ let admin_command_man = [
holding package definition within subdirectories. A 'compilers%s' \
subdirectory (opam repository format version < 2) will also be used by \
the $(b,upgrade-format) subcommand."
Filename.dir_sep Filename.dir_sep |> Cmdliner.Manpage.escape)
OpamArg.dir_sep OpamArg.dir_sep)
]

let index_command_doc =
Expand Down Expand Up @@ -198,7 +198,8 @@ let cache_command =
info ["link"] ~docv:"DIR" ~doc:
(Printf.sprintf
"Create reverse symbolic links to the archives within $(i,DIR), in \
the form $(b,DIR%sPKG.VERSION%sFILENAME)." Filename.dir_sep Filename.dir_sep |> Cmdliner.Manpage.escape))
the form $(b,DIR%sPKG.VERSION%sFILENAME)."
OpamArg.dir_sep OpamArg.dir_sep))
in
let jobs_arg =
Arg.(value & opt OpamArg.positive_integer 8 &
Expand Down Expand Up @@ -266,7 +267,7 @@ let add_hashes_command =
"This command scans through package definitions, and add hashes as \
requested (fetching the archives if required). A cache is generated \
in %s for subsequent runs."
(OpamFilename.Dir.to_string cache_dir |> Cmdliner.Manpage.escape));
(OpamArg.escape_path (OpamFilename.Dir.to_string cache_dir)));
]
in
let hash_kinds = [`MD5; `SHA256; `SHA512] in
Expand Down Expand Up @@ -494,15 +495,16 @@ let upgrade_command =
converts them to repositories suitable for the current opam version. \
Packages might be created or renamed, and any compilers defined in the \
old format ('compilers%s' directory) will be turned into packages, \
using a pre-defined hierarchy that assumes OCaml compilers." Filename.dir_sep |> Cmdliner.Manpage.escape)
using a pre-defined hierarchy that assumes OCaml compilers."
OpamArg.dir_sep)
]
in
let clear_cache_arg =
let doc =
Printf.sprintf
"Instead of running the upgrade, clear the cache of archive hashes (held \
in ~%s.cache), that is used to avoid re-downloading files to obtain \
their hashes at every run." Filename.dir_sep |> Cmdliner.Manpage.escape
their hashes at every run." OpamArg.dir_sep
in
Arg.(value & flag & info ["clear-cache"] ~doc)
in
Expand Down Expand Up @@ -718,7 +720,8 @@ let env_arg =
resolved purely from globally defined variables. Note that, unless \
overridden, variables like 'root' or 'opam-version' may be taken \
from the current opam installation. What is defined in \
$(i,~%s.opam%sconfig) is always ignored." Filename.dir_sep Filename.dir_sep |> Cmdliner.Manpage.escape))
$(i,~%s.opam%sconfig) is always ignored."
OpamArg.dir_sep OpamArg.dir_sep))

let state_selection_arg =
let docs = OpamArg.package_selection_section in
Expand Down
20 changes: 16 additions & 4 deletions src/client/opamArg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,18 @@ let help_sections = [
]

(* Converters *)

(* Windows directory separator need to be escaped for manpage *)
let dir_sep, escape_path =
match Filename.dir_sep with
| "\\" ->
let esc = "\\\\" in
esc,
fun p ->
OpamStd.List.concat_map esc (fun x -> x)
(OpamStd.String.split_delim p '\\')
| ds -> ds, fun x -> x

let pr_str = Format.pp_print_string

let repository_name =
Expand Down Expand Up @@ -442,7 +454,7 @@ let existing_filename_or_dash =

let dirname =
let parse str = `Ok (OpamFilename.Dir.of_string str) in
let print ppf dir = pr_str ppf (OpamFilename.prettify_dir dir) in
let print ppf dir = pr_str ppf (escape_path (OpamFilename.prettify_dir dir)) in
parse, print

let existing_filename_dirname_or_dash =
Expand Down Expand Up @@ -871,7 +883,7 @@ let dot_profile_flag =
(Printf.sprintf
"Name of the configuration file to update instead of \
$(i,~%s.profile) or $(i,~%s.zshrc) based on shell detection."
Filename.dir_sep Filename.dir_sep |> Cmdliner.Manpage.escape)
dir_sep dir_sep)
(Arg.some filename) None

let repo_kind_flag =
Expand Down Expand Up @@ -913,15 +925,15 @@ let atom_or_local_list =
(Printf.sprintf
"List of package names, with an optional version or constraint, e.g `pkg', \
`pkg.1.0' or `pkg>=0.5' ; or files or directory names containing package \
description, with explicit directory (e.g. `.%sfoo.opam' or `.')" Filename.dir_sep |> Cmdliner.Manpage.escape)
description, with explicit directory (e.g. `.%sfoo.opam' or `.')" dir_sep)
atom_or_local

let atom_or_dir_list =
arg_list "PACKAGES"
(Printf.sprintf
"List of package names, with an optional version or constraint, e.g `pkg', \
`pkg.1.0' or `pkg>=0.5' ; or directory names containing package \
description, with explicit directory (e.g. `.%ssrcdir' or `.')" Filename.dir_sep |> Cmdliner.Manpage.escape)
description, with explicit directory (e.g. `.%ssrcdir' or `.')" dir_sep)
atom_or_dir

let nonempty_atom_list =
Expand Down
7 changes: 7 additions & 0 deletions src/client/opamArg.mli
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ val mk_opt_all:
string list -> string -> string ->
'a Arg.converter -> 'a list Term.t

(* Escaped Windows directory separator. To use instead of [Filename.dir_sep] for
manpage strings *)
val dir_sep: string

(* Escape Windows path *)
val escape_path: string -> string

(** {2 Flags} *)

(** --short *)
Expand Down
16 changes: 9 additions & 7 deletions src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ let global_options =
mk_flag ~section:global_option_section ["no-self-upgrade"]
(Printf.sprintf
"Opam will replace itself with a newer binary found \
at $(b,OPAMROOT%sopam) if present. This disables this behaviour." Filename.dir_sep |> Cmdliner.Manpage.escape) in
at $(b,OPAMROOT%sopam) if present. This disables this behaviour."
OpamArg.dir_sep) in
let self_upgrade no_self_upgrade options =
let self_upgrade_status =
if OpamStd.Config.env_string "NOSELFUPGRADE" =
Expand Down Expand Up @@ -178,11 +179,11 @@ let init =
installed, according to the configuration and options. These can be \
afterwards configured using $(b,opam switch) and $(b,opam \
repository)."
Filename.dir_sep Filename.dir_sep |> Cmdliner.Manpage.escape);
OpamArg.dir_sep OpamArg.dir_sep);
`P (Printf.sprintf
"The initial repository and defaults can be set through a \
configuration file found at $(i,~%s.opamrc) or $(i,/etc/opamrc)."
Filename.dir_sep |> Cmdliner.Manpage.escape);
OpamArg.dir_sep);
`P "Additionally, this command allows one to customise some aspects of opam's \
shell integration, when run initially (avoiding the interactive \
dialog), but also at any later time.";
Expand All @@ -194,7 +195,7 @@ let init =
through $(i,~%s.opamrc), $(i,/etc/opamrc), or a file supplied with \
$(i,--config). The default configuration for this version of opam \
can be obtained using $(b,--show-default-opamrc)."
Filename.dir_sep |> Cmdliner.Manpage.escape);
OpamArg.dir_sep);
] @ OpamArg.man_build_option_section
in
let compiler =
Expand Down Expand Up @@ -274,7 +275,7 @@ let init =
mk_flag ["no-opamrc"]
(Printf.sprintf
"Don't read `/etc/opamrc' or `~%s.opamrc': use the default settings and \
the files specified through $(b,--config) only" Filename.dir_sep |> Cmdliner.Manpage.escape)
the files specified through $(b,--config) only" OpamArg.dir_sep)
in
let reinit =
mk_flag ["reinit"]
Expand Down Expand Up @@ -2274,7 +2275,7 @@ let switch =
package definitions are found locally, the user is automatically \
prompted to install them after the switch is created unless \
$(b,--no-install) is specified."
Filename.dir_sep OpamSwitch.external_dirname |> Cmdliner.Manpage.escape);
OpamArg.dir_sep OpamSwitch.external_dirname);
`P "$(b,opam switch set) sets the default switch globally, but it is also \
possible to select a switch in a given shell session, using the \
environment. For that, use $(i,eval \\$(opam env \
Expand Down Expand Up @@ -3344,7 +3345,8 @@ let clean =
mk_flag ["c"; "download-cache"]
(Printf.sprintf
"Clear the cache of downloaded files (\\$OPAMROOT%sdownload-cache), as \
well as the obsolete \\$OPAMROOT%sarchives, if that exists." Filename.dir_sep Filename.dir_sep |> Cmdliner.Manpage.escape)
well as the obsolete \\$OPAMROOT%sarchives, if that exists."
OpamArg.dir_sep OpamArg.dir_sep)
in
let repos =
mk_flag ["unused-repositories"]
Expand Down

0 comments on commit 8520b17

Please sign in to comment.