Skip to content

Commit

Permalink
New documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-zherikov committed Jun 26, 2024
1 parent 97bee99 commit c18b32c
Show file tree
Hide file tree
Showing 117 changed files with 3,268 additions and 87 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Build documentation

on:
push:
branches: ["master"]
pull_request:

# Gives the workflow permissions to clone the repo and create a page deployment
permissions:
id-token: write
pages: write

env:
# Name of help module and instance id separated by a slash
INSTANCE: docs/ad
# AD = the ID of the instance in capital letters
ARTIFACT: webHelpAD2-all.zip
# Writerside docker image version
DOCKER_VERSION: 241.15989
# Add the variable below to upload Algolia indexes
# AD = the ID of the instance in capital letters
ALGOLIA_ARTIFACT: algolia-indexes-AD.zip

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build Writerside docs using Docker
uses: JetBrains/writerside-github-action@v4
with:
instance: ${{ env.INSTANCE }}
artifact: ${{ env.ARTIFACT }}
docker-version: ${{ env.DOCKER_VERSION }}

- name: Upload documentation
uses: actions/upload-artifact@v4
with:
name: docs
retention-days: 7
path: |
artifacts/${{ env.ARTIFACT }}
artifacts/report.json
# Add the step below to upload Algolia indexes
- name: Upload algolia-indexes
uses: actions/upload-artifact@v4
with:
name: algolia-indexes
retention-days: 7
path: artifacts/${{ env.ALGOLIA_ARTIFACT }}

# fail the build when documentation contains errors
test:
# Requires build job results
needs: build
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: docs
path: artifacts

- name: Test documentation
uses: JetBrains/writerside-checker-action@v1
with:
instance: ${{ env.INSTANCE }}

deploy:
if: ${{ github.ref_name == 'master' }}
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
# Requires the test job results
needs: test
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: docs

- name: Unzip artifact
run: unzip -O UTF-8 -qq ${{ env.ARTIFACT }} -d dir

- name: Setup Pages
uses: actions/configure-pages@v4

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: dir

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
out/
docs.json
__dummy.html
docs/
/argparse
argparse.iml
*argparse.so
Expand Down
45 changes: 45 additions & 0 deletions docs/ad.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE instance-profile
SYSTEM "https://resources.jetbrains.com/writerside/1.0/product-profile.dtd">

<instance-profile id="ad"
name="argparse documentation"
start-page="Introduction.md">

<toc-element topic="Introduction.md"/>
<toc-element topic="Getting-started.md"/>
<toc-element topic="Arguments.md">
<toc-element topic="Positional-arguments.md"/>
<toc-element topic="Named-arguments.md">
<toc-element topic="Arguments-bundling.md"/>
<toc-element topic="End-of-named-arguments.md"/>
</toc-element>
<toc-element topic="Supported-types.md"/>
<toc-element topic="Arity.md"/>
<toc-element topic="Optional-and-required-arguments.md"/>
<toc-element topic="Restrict-allowed-values.md"/>
<toc-element topic="Parsing-customization.md"/>
</toc-element>
<toc-element topic="Argument-dependencies.md"/>
<toc-element topic="Calling-the-parser.md"/>
<toc-element topic="ANSI-coloring-and-styling.md"/>
<toc-element topic="Subcommands.md"/>
<toc-element topic="Help-generation.md"/>
<toc-element topic="Shell-completion.md"/>
<toc-element toc-title="Reference">
<toc-element topic="CLI-API.md"/>
<toc-element topic="Config.md"/>
<toc-element topic="Param-RawParam.md"/>
<toc-element topic="Result.md"/>
<toc-element toc-title="UDAs">
<toc-element topic="ArgumentGroup.md"/>
<toc-element topic="ArgumentValue.md"/>
<toc-element topic="Command.md"/>
<toc-element topic="MutuallyExclusive.md"/>
<toc-element topic="PositionalNamedArgument.md"/>
<toc-element topic="RequiredTogether.md"/>
</toc-element>
<toc-element topic="SubCommand.md"/>
<toc-element topic="ansiStylingArgument.md"/>
</toc-element>
</instance-profile>
6 changes: 6 additions & 0 deletions docs/c.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE categories
SYSTEM "https://resources.jetbrains.com/writerside/1.0/categories.dtd">
<categories>
<category id="wrs" name="Writerside documentation" order="1"/>
</categories>
12 changes: 12 additions & 0 deletions docs/cfg/buildprofiles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<buildprofiles xsi:noNamespaceSchemaLocation="https://resources.jetbrains.com/writerside/1.0/build-profiles.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<variables></variables>
<build-profile instance="ad">
<variables>
<noindex-content>false</noindex-content>
</variables>
</build-profile>

</buildprofiles>
14 changes: 14 additions & 0 deletions docs/code_snippets/allowed_values.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import argparse;

struct T
{
@(NamedArgument.AllowedValues!(["apple","pear","banana"]))
string fruit;
}

T t;
assert(CLI!T.parseArgs(t, ["--fruit", "apple"]));
assert(t == T("apple"));

// "kiwi" is not allowed
assert(!CLI!T.parseArgs(t, ["--fruit", "kiwi"]));
20 changes: 20 additions & 0 deletions docs/code_snippets/ansiStylingArgument.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import argparse;

struct T
{
static auto color = ansiStylingArgument;
}

T t;
CLI!T.parseArgs(t, ["-h"]);

// This is a way to detect whether `--color` argument was specified in the command line
// Note that 'autodetect' is converted to either 'on' or 'off'
assert(CLI!T.parseArgs(t, ["--color"]));
assert(t.color);

assert(CLI!T.parseArgs(t, ["--color=always"]));
assert(t.color);

assert(CLI!T.parseArgs(t, ["--color=never"]));
assert(!t.color);
13 changes: 13 additions & 0 deletions docs/code_snippets/arity.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import argparse;

struct T
{
@(NamedArgument.NumberOfValues(1,3))
int[] a;
@(NamedArgument.NumberOfValues(2))
int[] b;
}

T t;
assert(CLI!T.parseArgs(t, ["-a","1","2","3","-b","4","5"]));
assert(t == T([1,2,3], [4,5]));
19 changes: 19 additions & 0 deletions docs/code_snippets/arity_no_values.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import argparse;

struct T
{
@(NamedArgument.AllowNoValue !10) int a;
@(NamedArgument.RequireNoValue!20) int b;
}

T t;
assert(CLI!T.parseArgs(t, ["-a"]));
assert(t.a == 10);

assert(CLI!T.parseArgs(t, ["-b"]));
assert(t.b == 20);

assert(CLI!T.parseArgs(t, ["-a","30"]));
assert(t.a == 30);

assert(!CLI!T.parseArgs(t, ["-b","30"])); // Unrecognized arguments: ["30"]
18 changes: 18 additions & 0 deletions docs/code_snippets/call_parser1.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import argparse;

struct T
{
string a;
string b;
}

mixin CLI!T.main!((args)
{
// 'args' has 'T' type
static assert(is(typeof(args) == T));

// do whatever you need
import std.stdio: writeln;
args.writeln;
return 0;
});
27 changes: 27 additions & 0 deletions docs/code_snippets/call_parser2.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import argparse;

struct cmd1
{
string a;
}

struct cmd2
{
string b;
}

mixin CLI!(cmd1, cmd2).main!((args, unparsed)
{
// 'args' has either 'cmd1' or 'cmd2' type
static if(is(typeof(args) == cmd1))
writeln("cmd1: ", args);
else static if(is(typeof(args) == cmd2))
writeln("cmd2: ", args);
else
static assert(false); // this would never happen

// unparsed arguments has 'string[]' type
static assert(is(typeof(unparsed) == string[]));

return 0;
});
21 changes: 21 additions & 0 deletions docs/code_snippets/call_parser3.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import argparse;

struct COMMAND
{
string a;
string b;
}

static int my_main(COMMAND command)
{
// Do whatever is needed
return 0;
}

int main(string[] args)
{
// Do initialization here
// If needed, termination code can be done as 'scope(exit) { ...code... }' here as well

return CLI!COMMAND.parseArgs!my_main(args[1..$]);
}
19 changes: 19 additions & 0 deletions docs/code_snippets/call_parser4.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import argparse;

struct COMMAND
{
string a;
string b;
}

int main(string[] argv)
{
COMMAND cmd;

if(!CLI!COMMAND.parseArgs(cmd, argv[1..$]))
return 1; // parsing failure

// Do whatever is needed

return 0;
}
13 changes: 13 additions & 0 deletions docs/code_snippets/call_parser5.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import argparse;

struct T
{
string a;
}

auto arguments = [ "-a", "A", "-c", "C" ];

T result;
assert(CLI!T.parseKnownArgs(result, arguments));
assert(result == T("A"));
assert(arguments == ["-c", "C"]);
18 changes: 18 additions & 0 deletions docs/code_snippets/config_addHelp.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import argparse;

struct T
{
string a, b;
}

T t1;
CLI!T.parseArgs(t1, ["-a", "A", "-h", "-b", "B"]);
assert(t1 == T("A"));

enum Config cfg = { addHelp: false };

T t2;
string[] unrecognizedArgs;
CLI!(cfg, T).parseKnownArgs(t2, ["-a", "A", "-h", "-b", "B"], unrecognizedArgs);
assert(t2 == T("A","B"));
assert(unrecognizedArgs == ["-h"]);
16 changes: 16 additions & 0 deletions docs/code_snippets/config_arraySep.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import argparse;

struct T
{
string[] a;
}

T t1;
assert(CLI!T.parseArgs(t1, ["-a","1:2:3","-a","4","5"]));
assert(t1 == T(["1:2:3","4","5"]));

enum Config cfg = { arraySep: ':' };

T t2;
assert(CLI!(cfg, T).parseArgs(t2, ["-a","1:2:3","-a","4","5"]));
assert(t2 == T(["1","2","3","4","5"]));
12 changes: 12 additions & 0 deletions docs/code_snippets/config_assignChar.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import argparse;

struct T
{
string[] a;
}

enum Config cfg = { assignChar: ':' };

T t;
assert(CLI!(cfg, T).parseArgs(t, ["-a:1","-a:2","-a:3"]));
assert(t == T(["1","2","3"]));
Loading

0 comments on commit c18b32c

Please sign in to comment.