R Under development (unstable) (2024-01-14 r85805 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(port4me) > > Sys.setenv("_PORT4ME_CHECK_AVAILABLE_PORTS_" = "any") > > # -------------------------------------------------------- > # Test CLI app > # -------------------------------------------------------- > message("CLI: No options (default)") CLI: No options (default) > print(port4me) 51062 > > message("CLI: Explicitly no options (default)") CLI: Explicitly no options (default) > options(.port4me.commandArgs = c()) > print(port4me) 51062 > > message("CLI: --debug") CLI: --debug > options(.port4me.commandArgs = c("--debug")) > print(port4me) seed_str='CRAN' seed=2076892 List of 3 $ include: int(0) $ exclude: int [1:80] 1 7 9 11 13 15 17 19 20 21 ... $ prepend: int(0) 51062 > > message("CLI: --help") CLI: --help > options(.port4me.commandArgs = c("--help")) > print(port4me) port4me: Get the Same, Personal, Free 'TCP' Port over and over Usage: Rscript -e port4me::port4me [options] Options: --help Display the full help page with examples --version Output version of this software --debug Output detailed debug information --user= User name (default: $USER) --tool= Name of software tool --include= Set of ports to be included (default: 1024-65535) --exclude= Set of ports to be excluded --prepend= Set of ports to be considered first --skip= Number of ports to skip --list= List the first 'n', available or not, ports --test= Return 0 if port is available, otherwise 1 Examples: Rscript -e port4me::port4me --version Rscript -e port4me::port4me Rscript -e port4me::port4me --tool=rstudio Rscript -e port4me::port4me --include=11000-11999 --exclude=11500,11509 --tool=rstudio Rscript -e port4me::port4me rstudio ## short for --tool=rstudio rserver --www-port "$(Rscript -e port4me::port4me rstudio)" jupyter notebook --port "$(Rscript -e port4me::port4me jupyter-notebook)" Rscript -e port4me::port4me --test=8087 && echo "free" || echo "taken" Version: 0.7.0 Copyright: Henrik Bengtsson (2022-2024) License: MIT > > message("CLI: --version") CLI: --version > options(.port4me.commandArgs = c("--version")) > print(port4me) 0.7.0 > > message('CLI: --user="alice"') CLI: --user="alice" > options(.port4me.commandArgs = c('--user="alice"')) > print(port4me) seed_str='"alice"' seed=2990348356 List of 3 $ include: int(0) $ exclude: int [1:80] 1 7 9 11 13 15 17 19 20 21 ... $ prepend: int(0) 58501 > > message('CLI: --user="alice" --tool="rstudio"') CLI: --user="alice" --tool="rstudio" > options(.port4me.commandArgs = c('--user="alice"', '--tool="rstudio"')) > print(port4me) seed_str='"alice","rstudio"' seed=1199132436 List of 3 $ include: int(0) $ exclude: int [1:80] 1 7 9 11 13 15 17 19 20 21 ... $ prepend: int(0) 15025 > > message('CLI: --user="alice" rstudio') CLI: --user="alice" rstudio > options(.port4me.commandArgs = c('--user="alice"', 'rstudio')) > print(port4me) seed_str='"alice",rstudio' seed=635656032 List of 3 $ include: int(0) $ exclude: int [1:80] 1 7 9 11 13 15 17 19 20 21 ... $ prepend: int(0) 32731 > > message('CLI: --foo') CLI: --foo > options(.port4me.commandArgs = c('--foo')) > res <- tryCatch({ + print(port4me) + }, error = identity) > stopifnot(inherits(res, "error")) > > message('CLI: --foo=bar') CLI: --foo=bar > options(.port4me.commandArgs = c('--foo=bar')) > res <- tryCatch({ + print(port4me) + }, error = identity) > stopifnot(inherits(res, "error")) > > > message('CLI: --123') CLI: --123 > options(.port4me.commandArgs = c('--123')) > res <- tryCatch({ + print(port4me) + }, error = identity) > stopifnot(inherits(res, "error")) > > > ## This needs to be last, because it calls quit() > message('CLI: --test=80') CLI: --test=80 > options(.port4me.commandArgs = c('--test=80')) > print(port4me) seed_str='CRAN' seed=2076892 > proc.time() user system elapsed 0.23 0.06 0.23