Skip to content

Commit

Permalink
Rewrite in Go
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Nov 23, 2021
1 parent 791a0c4 commit 161d935
Show file tree
Hide file tree
Showing 27 changed files with 306 additions and 1,586 deletions.
53 changes: 0 additions & 53 deletions .github/workflows/ci.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
.DS_Store
dist
*.log
aho
1 change: 0 additions & 1 deletion .prettierrc

This file was deleted.

16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,17 @@

# aho

[![npm version](https://badgen.net/npm/v/aho)](https://npm.im/aho) [![npm downloads](https://badgen.net/npm/dm/aho)](https://npm/im/aho) [![install size](https://packagephobia.com/badge?p=aho)](https://packagephobia.com/result?p=aho)

> ultra simple project scaffolding
## Usage

With Node.js:
## Install

```bash
# NPM
npx aho user/repo [destination]
# PNPM
pnpm dlx aho user/repo [destination]
curl -sf https://gobinaries.com/egoist/aho | sh
```

With Deno:
## Usage

```bash
deno install --allow-net --allow-read --allow-write --allow-run \
https://denopkg.com/egoist/aho@latest/aho.ts

aho user/repo [destination]
```

Expand Down
17 changes: 0 additions & 17 deletions aho.code-workspace

This file was deleted.

3 changes: 0 additions & 3 deletions aho.ts

This file was deleted.

109 changes: 109 additions & 0 deletions args.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package main

import (
_ "embed"
"fmt"
"os"
"path"
"strings"
)

type AppArgs struct {
repo string
destination string
force bool
subpath string
}

func parseArgs(args []string) (*AppArgs, error) {
appArgs := new(AppArgs)
repo := ""
force := false
subpath := ""
destination := ""
help := false
version := false

for index := 0; index < len(args); index++ {
arg := args[index]
if strings.HasPrefix(arg, "-") {
if arg == "-f" || arg == "--force" {
force = true
} else if arg == "-h" || arg == "--help" {
help = true
} else if arg == "-v" || arg == "--version" {
version = true
} else if arg == "-p" || arg == "--path" {
v := ""
if index+1 <= len(args)-1 {
v = args[index+1]
}
if v == "" {
return nil, fmt.Errorf("missing path value")
}
subpath = v
index += 1
} else {
return nil, fmt.Errorf("unknown flag: %s", arg)
}
} else {
if repo == "" {
repo = arg
} else if destination == "" {
destination = arg
} else {
return nil, fmt.Errorf("too many arguments: %s", arg)
}
}

}

if version {
PrintVersion()
os.Exit(0)
}

if help {
PrintHelp()
os.Exit(0)
}

if repo == "" {
return nil, fmt.Errorf("missing repo")
}

appArgs.repo = repo
appArgs.force = force
appArgs.subpath = subpath

if destination == "" {
// set destination to current directory with absolute path
appArgs.destination = GetCurrentDirectory()
} else {
appArgs.destination = path.Join(GetCurrentDirectory(), destination)
}

return appArgs, nil
}

func GetCurrentDirectory() string {
dir, err := os.Getwd()
if err != nil {
panic(err)
}
return dir
}

//go:embed version.txt
var version string

//go:embed help.txt
var help string

func PrintHelp() {
fmt.Printf(help, version)
}

func PrintVersion() {
fmt.Println(version)
}
4 changes: 0 additions & 4 deletions cli-node.js

This file was deleted.

1 change: 0 additions & 1 deletion deno/README.md

This file was deleted.

71 changes: 0 additions & 71 deletions deno/deno/lib.ts

This file was deleted.

0 comments on commit 161d935

Please sign in to comment.