Skip to content

Commit

Permalink
feat(args): now receives arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-apprentice committed May 3, 2024
1 parent 710ba83 commit d4b633c
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
# docs-generator

Create your own documentation with ease!

## Usage

```bash
$ my-docs --help
$ my-docs --version
$ my-docs --generate
$ my-docs --validate
```

## Download

Check at the [releases](/~https://github.com/jd-apprentice/my-docs/releases) page.
55 changes: 51 additions & 4 deletions lib/my-docs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const std = @import("std");
const fs = std.fs;

//--------- Constants ---------//
const app_version = "0.1.0";
const docs_files: [2][]const u8 = [2][]const u8{
"CNAME",
"index.md",
Expand Down Expand Up @@ -103,10 +104,7 @@ fn about(image: [1][]const u8) !void {
try printLine();
}

//--------- App ---------//
pub fn main() !void {
try about(logo);

fn generateFiles() !void {
const cwd = fs.cwd();
var rootDir = try cwd.openDir("./", .{});
defer rootDir.close();
Expand Down Expand Up @@ -141,3 +139,52 @@ pub fn main() !void {
try printLine();
std.debug.print("You can create .md files in the docs folder and push to the repository\n", .{});
}

fn validateFiles() !void {
std.debug.print("TODO\n", .{});
}

fn printHelp() !void {
std.debug.print("Usage: my-docs --generate\n", .{});
std.debug.print("Usage: my-docs --validate\n", .{});
std.process.exit(1);
}

fn printVersion() !void {
std.debug.print("Version: {s}\n", .{app_version});
}

pub fn main() !void {
try about(logo);

var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
defer _ = gpa.deinit();

const args = try std.process.argsAlloc(allocator);
defer std.process.argsFree(allocator, args);

if (args.len < 2) {
std.debug.print("Usage: my-docs --help\n", .{});
std.process.exit(1);
}

const arg = args[1];
const help = "--help";
const generate = "--generate";
const version = "--version";
const validate = "--validate";

const isGenerate = std.mem.eql(u8, arg, generate);
const isHelp = std.mem.eql(u8, arg, help);
const isVersion = std.mem.eql(u8, arg, version);
const isValidate = std.mem.eql(u8, arg, validate);

if (isHelp) try printHelp();
if (isVersion) try printVersion();
if (isValidate) try validateFiles();
if (isGenerate) try generateFiles();

try printHelp();
std.process.exit(0);
}

0 comments on commit d4b633c

Please sign in to comment.