@0010capacity/reddit-cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -0
- package/bin/reddit-cli.js +21 -0
- package/install.js +82 -0
- package/package.json +35 -0
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# @reddit-cli/cli
|
|
2
|
+
|
|
3
|
+
A powerful CLI client for Reddit, written in Rust.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @reddit-cli/cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# View hot posts
|
|
15
|
+
reddit hot
|
|
16
|
+
|
|
17
|
+
# View a specific subreddit
|
|
18
|
+
reddit subreddit show rust
|
|
19
|
+
|
|
20
|
+
# Search Reddit
|
|
21
|
+
reddit search "rust programming" --subreddit rust
|
|
22
|
+
|
|
23
|
+
# Login for full access
|
|
24
|
+
reddit auth login
|
|
25
|
+
|
|
26
|
+
# After login, access your account
|
|
27
|
+
reddit me
|
|
28
|
+
reddit me karma
|
|
29
|
+
|
|
30
|
+
# Subscribe to a subreddit
|
|
31
|
+
reddit subscribe rust
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Commands
|
|
35
|
+
|
|
36
|
+
### Browsing (No Auth Required)
|
|
37
|
+
|
|
38
|
+
| Command | Description |
|
|
39
|
+
|---------|-------------|
|
|
40
|
+
| `reddit hot` | View hot posts |
|
|
41
|
+
| `reddit new` | View new posts |
|
|
42
|
+
| `reddit top [--time hour/day/week/month/year/all]` | View top posts |
|
|
43
|
+
| `reddit rising` | View rising posts |
|
|
44
|
+
| `reddit controversial` | View controversial posts |
|
|
45
|
+
| `reddit subreddit show <name>` | View subreddit info |
|
|
46
|
+
| `reddit user show <username>` | View user info |
|
|
47
|
+
| `reddit search <query>` | Search Reddit |
|
|
48
|
+
|
|
49
|
+
### Account (Auth Required)
|
|
50
|
+
|
|
51
|
+
| Command | Description |
|
|
52
|
+
|---------|-------------|
|
|
53
|
+
| `reddit me` | View your account info |
|
|
54
|
+
| `reddit me karma` | View karma breakdown |
|
|
55
|
+
| `reddit me subreddits` | View subscribed subreddits |
|
|
56
|
+
|
|
57
|
+
### Interactions (Auth Required)
|
|
58
|
+
|
|
59
|
+
| Command | Description |
|
|
60
|
+
|---------|-------------|
|
|
61
|
+
| `reddit upvote <id>` | Upvote a post/comment |
|
|
62
|
+
| `reddit downvote <id>` | Downvote a post/comment |
|
|
63
|
+
| `reddit save <id>` | Save a post/comment |
|
|
64
|
+
| `reddit subscribe <subreddit>` | Subscribe to subreddit |
|
|
65
|
+
|
|
66
|
+
### Posting (Auth Required)
|
|
67
|
+
|
|
68
|
+
| Command | Description |
|
|
69
|
+
|---------|-------------|
|
|
70
|
+
| `reddit submit link -r <sr> -t <title> -u <url>` | Submit a link |
|
|
71
|
+
| `reddit submit text -r <sr> -t <title> --text <body>` | Submit a text post |
|
|
72
|
+
| `reddit comment <parent> --text <text>` | Post a comment |
|
|
73
|
+
|
|
74
|
+
### Moderation (Auth + Mod Required)
|
|
75
|
+
|
|
76
|
+
| Command | Description |
|
|
77
|
+
|---------|-------------|
|
|
78
|
+
| `reddit mod reports <subreddit>` | View reports |
|
|
79
|
+
| `reddit mod queue <subreddit>` | View mod queue |
|
|
80
|
+
| `reddit mod approve <id>` | Approve post/comment |
|
|
81
|
+
| `reddit mod remove <id>` | Remove post/comment |
|
|
82
|
+
|
|
83
|
+
## Output Formats
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# Table format (default)
|
|
87
|
+
reddit hot
|
|
88
|
+
|
|
89
|
+
# JSON output
|
|
90
|
+
reddit hot --format json
|
|
91
|
+
|
|
92
|
+
# Plain text
|
|
93
|
+
reddit hot --format plain
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Authentication
|
|
97
|
+
|
|
98
|
+
Reddit CLI uses OAuth2 for authentication. On first use:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
reddit auth login
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
This will open your browser for authentication.
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
MIT
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn } = require('child_process');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const binaryName = process.platform === 'win32' ? 'reddit-cli.exe' : 'reddit-cli';
|
|
7
|
+
const binaryPath = path.join(__dirname, '..', 'binaries', binaryName);
|
|
8
|
+
|
|
9
|
+
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
10
|
+
stdio: 'inherit',
|
|
11
|
+
env: process.env
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
child.on('exit', (code) => {
|
|
15
|
+
process.exit(code || 0);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
child.on('error', (err) => {
|
|
19
|
+
console.error('Failed to run reddit-cli:', err.message);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
});
|
package/install.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const https = require('https');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { execSync } = require('child_process');
|
|
5
|
+
|
|
6
|
+
const VERSION = '0.1.0';
|
|
7
|
+
const GITHUB_REPO = 'yourusername/reddit-cli';
|
|
8
|
+
|
|
9
|
+
function getPlatform() {
|
|
10
|
+
const platform = process.platform;
|
|
11
|
+
const arch = process.arch;
|
|
12
|
+
|
|
13
|
+
const map = {
|
|
14
|
+
'darwin-x64': 'x86_64-apple-darwin',
|
|
15
|
+
'darwin-arm64': 'aarch64-apple-darwin',
|
|
16
|
+
'linux-x64': 'x86_64-unknown-linux-gnu',
|
|
17
|
+
'linux-arm64': 'aarch64-unknown-linux-gnu',
|
|
18
|
+
'win32-x64': 'x86_64-pc-windows-msvc'
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const key = `${platform}-${arch}`;
|
|
22
|
+
return map[key] || null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function download(url, dest) {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
const file = fs.createWriteStream(dest);
|
|
28
|
+
https.get(url, (response) => {
|
|
29
|
+
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
30
|
+
download(response.headers.location, dest).then(resolve).catch(reject);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
response.pipe(file);
|
|
34
|
+
file.on('finish', () => {
|
|
35
|
+
file.close();
|
|
36
|
+
resolve();
|
|
37
|
+
});
|
|
38
|
+
}).on('error', (err) => {
|
|
39
|
+
fs.unlink(dest, () => {});
|
|
40
|
+
reject(err);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function install() {
|
|
46
|
+
const platform = getPlatform();
|
|
47
|
+
|
|
48
|
+
if (!platform) {
|
|
49
|
+
console.error(`Unsupported platform: ${process.platform}-${process.arch}`);
|
|
50
|
+
console.log('Please build from source: cargo install --path .');
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const binDir = path.join(__dirname, 'binaries');
|
|
55
|
+
if (!fs.existsSync(binDir)) {
|
|
56
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const ext = process.platform === 'win32' ? '.exe' : '';
|
|
60
|
+
const binaryName = `reddit-cli-${platform}${ext}`;
|
|
61
|
+
const downloadUrl = `https://github.com/${GITHUB_REPO}/releases/download/v${VERSION}/${binaryName}`;
|
|
62
|
+
const destPath = path.join(binDir, `reddit-cli${ext}`);
|
|
63
|
+
|
|
64
|
+
console.log(`Downloading reddit-cli v${VERSION} for ${platform}...`);
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
await download(downloadUrl, destPath);
|
|
68
|
+
|
|
69
|
+
// Make executable on Unix
|
|
70
|
+
if (process.platform !== 'win32') {
|
|
71
|
+
fs.chmodSync(destPath, 0o755);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
console.log('reddit-cli installed successfully!');
|
|
75
|
+
} catch (err) {
|
|
76
|
+
console.error('Failed to download binary:', err.message);
|
|
77
|
+
console.log('Please build from source: cargo install --path .');
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
install();
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@0010capacity/reddit-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A powerful CLI client for Reddit",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"reddit",
|
|
7
|
+
"cli",
|
|
8
|
+
"api",
|
|
9
|
+
"client"
|
|
10
|
+
],
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/yourusername/reddit-cli.git"
|
|
16
|
+
},
|
|
17
|
+
"bin": {
|
|
18
|
+
"reddit": "./bin/reddit-cli.js"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"postinstall": "node install.js"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"bin",
|
|
25
|
+
"install.js",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=16"
|
|
30
|
+
},
|
|
31
|
+
"optionalDependencies": {},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"ava": "^5.3.1"
|
|
34
|
+
}
|
|
35
|
+
}
|