ssh-keyman 1.0.2 → 2.0.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/.github/BADGE-SUMMARY.md +244 -0
- package/.github/BADGES.md +214 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +36 -0
- package/.github/workflows/ci.yml +69 -0
- package/.github/workflows/publish.yml +32 -0
- package/.github/workflows/test-report.yml +50 -0
- package/CONTRIBUTING.md +128 -0
- package/STATUS.md +134 -0
- package/codecov.yml +29 -0
- package/package.json +34 -3
- package/readme.md +160 -25
- package/src/__tests__/cliOptions.test.js +78 -0
- package/src/__tests__/commands.test.js +369 -0
- package/src/__tests__/constants.test.js +44 -0
- package/src/__tests__/extendFs.test.js +105 -0
- package/src/__tests__/helpers.js +113 -0
- package/src/__tests__/testUtils.js +113 -0
- package/src/commands.js +170 -96
- package/src/constants.js +7 -36
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Contributing to SSH KeyMan
|
|
2
|
+
|
|
3
|
+
First off, thank you for considering contributing to SSH KeyMan! It's people like you that make SSH KeyMan such a great tool.
|
|
4
|
+
|
|
5
|
+
## Code of Conduct
|
|
6
|
+
|
|
7
|
+
By participating in this project, you are expected to uphold our Code of Conduct:
|
|
8
|
+
- Be respectful and inclusive
|
|
9
|
+
- Welcome newcomers and help them learn
|
|
10
|
+
- Focus on what is best for the community
|
|
11
|
+
- Show empathy towards other community members
|
|
12
|
+
|
|
13
|
+
## How Can I Contribute?
|
|
14
|
+
|
|
15
|
+
### Reporting Bugs
|
|
16
|
+
|
|
17
|
+
Before creating bug reports, please check the existing issues to avoid duplicates. When you create a bug report, include as many details as possible:
|
|
18
|
+
|
|
19
|
+
- **Use a clear and descriptive title**
|
|
20
|
+
- **Describe the exact steps to reproduce the problem**
|
|
21
|
+
- **Provide specific examples**
|
|
22
|
+
- **Describe the behavior you observed and what you expected**
|
|
23
|
+
- **Include your environment details** (OS, Node.js version, etc.)
|
|
24
|
+
|
|
25
|
+
### Suggesting Enhancements
|
|
26
|
+
|
|
27
|
+
Enhancement suggestions are tracked as GitHub issues. When creating an enhancement suggestion:
|
|
28
|
+
|
|
29
|
+
- **Use a clear and descriptive title**
|
|
30
|
+
- **Provide a detailed description of the suggested enhancement**
|
|
31
|
+
- **Explain why this enhancement would be useful**
|
|
32
|
+
- **List any alternative solutions you've considered**
|
|
33
|
+
|
|
34
|
+
### Pull Requests
|
|
35
|
+
|
|
36
|
+
1. Fork the repo and create your branch from `master` or `main`
|
|
37
|
+
2. If you've added code that should be tested, add tests
|
|
38
|
+
3. If you've changed APIs, update the documentation
|
|
39
|
+
4. Ensure the test suite passes
|
|
40
|
+
5. Make sure your code follows the existing style
|
|
41
|
+
6. Issue the pull request!
|
|
42
|
+
|
|
43
|
+
## Development Setup
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# Clone your fork
|
|
47
|
+
git clone https://github.com/YOUR-USERNAME/ssh-keyman.git
|
|
48
|
+
|
|
49
|
+
# Navigate to the directory
|
|
50
|
+
cd ssh-keyman
|
|
51
|
+
|
|
52
|
+
# Install dependencies
|
|
53
|
+
npm install
|
|
54
|
+
|
|
55
|
+
# Run tests
|
|
56
|
+
npm test
|
|
57
|
+
|
|
58
|
+
# Run tests in watch mode (useful during development)
|
|
59
|
+
npm run test:watch
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Project Structure
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
ssh-keyman/
|
|
66
|
+
├── src/
|
|
67
|
+
│ ├── __tests__/ # Test files
|
|
68
|
+
│ │ ├── helpers.js # Test utilities
|
|
69
|
+
│ │ ├── *.test.js # Test files
|
|
70
|
+
│ ├── cli.js # CLI entry point
|
|
71
|
+
│ ├── cliOptions.js # CLI argument parsing
|
|
72
|
+
│ ├── commands.js # Command implementations
|
|
73
|
+
│ ├── constants.js # Constants and configuration
|
|
74
|
+
│ └── extendFs.js # File system utilities
|
|
75
|
+
├── .github/
|
|
76
|
+
│ └── workflows/ # GitHub Actions CI/CD
|
|
77
|
+
├── index.js # Main entry point
|
|
78
|
+
└── package.json
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Testing Guidelines
|
|
82
|
+
|
|
83
|
+
- Write tests for any new functionality
|
|
84
|
+
- Ensure all tests pass before submitting PR
|
|
85
|
+
- Aim for high code coverage (currently targeting 55%+)
|
|
86
|
+
- Use descriptive test names that explain what is being tested
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# Run all tests
|
|
90
|
+
npm test
|
|
91
|
+
|
|
92
|
+
# Run tests with coverage
|
|
93
|
+
npm run test:ci
|
|
94
|
+
|
|
95
|
+
# Run tests in watch mode
|
|
96
|
+
npm run test:watch
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Coding Style
|
|
100
|
+
|
|
101
|
+
- Use 2 spaces for indentation
|
|
102
|
+
- Use semicolons
|
|
103
|
+
- Use clear and descriptive variable names
|
|
104
|
+
- Add comments for complex logic
|
|
105
|
+
- Follow existing code patterns
|
|
106
|
+
|
|
107
|
+
## Commit Messages
|
|
108
|
+
|
|
109
|
+
- Use the present tense ("Add feature" not "Added feature")
|
|
110
|
+
- Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
|
|
111
|
+
- Limit the first line to 72 characters or less
|
|
112
|
+
- Reference issues and pull requests liberally after the first line
|
|
113
|
+
|
|
114
|
+
Example:
|
|
115
|
+
```
|
|
116
|
+
Add autocomplete for environment switching
|
|
117
|
+
|
|
118
|
+
- Implemented fuzzy search for environment names
|
|
119
|
+
- Added arrow key navigation
|
|
120
|
+
- Closes #123
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Questions?
|
|
124
|
+
|
|
125
|
+
Feel free to open an issue with your question or reach out to the maintainers directly.
|
|
126
|
+
|
|
127
|
+
Thank you for contributing! ❤️
|
|
128
|
+
|
package/STATUS.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Build & Test Status
|
|
2
|
+
|
|
3
|
+
## Current Status
|
|
4
|
+
|
|
5
|
+
### Build Status
|
|
6
|
+
[](https://github.com/shahidullahkhankhattak/ssh-keyman/actions/workflows/ci.yml)
|
|
7
|
+
|
|
8
|
+
**Latest Build:** ✅ Passing
|
|
9
|
+
|
|
10
|
+
### Test Status
|
|
11
|
+
[](https://github.com/shahidullahkhankhattak/ssh-keyman/actions/workflows/ci.yml)
|
|
12
|
+
|
|
13
|
+
**Total Tests:** 35
|
|
14
|
+
**Passing:** ✅ 35
|
|
15
|
+
**Failing:** ❌ 0
|
|
16
|
+
**Skipped:** ⏭️ 0
|
|
17
|
+
|
|
18
|
+
### Code Coverage
|
|
19
|
+
[](https://codecov.io/gh/shahidullahkhankhattak/ssh-keyman)
|
|
20
|
+
|
|
21
|
+
| Metric | Coverage | Status |
|
|
22
|
+
|--------|----------|--------|
|
|
23
|
+
| **Statements** | 75.11% | ✅ Passing |
|
|
24
|
+
| **Branches** | 54.73% | ✅ Passing |
|
|
25
|
+
| **Functions** | 65.71% | ✅ Passing |
|
|
26
|
+
| **Lines** | 76.27% | ✅ Passing |
|
|
27
|
+
|
|
28
|
+
### File Coverage
|
|
29
|
+
|
|
30
|
+
| File | Statements | Branches | Functions | Lines |
|
|
31
|
+
|------|-----------|----------|-----------|-------|
|
|
32
|
+
| `commands.js` | 78.91% | 57.83% | 55% | 80.62% |
|
|
33
|
+
| `cliOptions.js` | 60% | 0% | 81.81% | 59.25% |
|
|
34
|
+
| `constants.js` | 100% | 100% | 100% | 100% |
|
|
35
|
+
| `extendFs.js` | 100% | 100% | 100% | 100% |
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Platform Compatibility
|
|
40
|
+
|
|
41
|
+
### Operating Systems
|
|
42
|
+
|
|
43
|
+
| Platform | Node 16 | Node 18 | Node 20 | Status |
|
|
44
|
+
|----------|---------|---------|---------|--------|
|
|
45
|
+
| **Ubuntu** | ✅ | ✅ | ✅ | Passing |
|
|
46
|
+
| **macOS** | ✅ | ✅ | ✅ | Passing |
|
|
47
|
+
| **Windows** | ✅ | ✅ | ✅ | Passing |
|
|
48
|
+
|
|
49
|
+
### Test Suites
|
|
50
|
+
|
|
51
|
+
| Test Suite | Tests | Status |
|
|
52
|
+
|------------|-------|--------|
|
|
53
|
+
| `constants.test.js` | 7 tests | ✅ Passing |
|
|
54
|
+
| `extendFs.test.js` | 6 tests | ✅ Passing |
|
|
55
|
+
| `cliOptions.test.js` | 8 tests | ✅ Passing |
|
|
56
|
+
| `commands.test.js` | 14 tests | ✅ Passing |
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Performance Metrics
|
|
61
|
+
|
|
62
|
+
| Metric | Value |
|
|
63
|
+
|--------|-------|
|
|
64
|
+
| **Test Execution Time** | ~3.4s |
|
|
65
|
+
| **Package Size** | < 50KB |
|
|
66
|
+
| **Dependencies** | 4 |
|
|
67
|
+
| **Dev Dependencies** | 2 |
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## CI/CD Pipeline
|
|
72
|
+
|
|
73
|
+
### Workflows
|
|
74
|
+
|
|
75
|
+
1. **CI Workflow** (`ci.yml`)
|
|
76
|
+
- Runs on: Push, Pull Request
|
|
77
|
+
- Platforms: Ubuntu, macOS, Windows
|
|
78
|
+
- Node Versions: 16.x, 18.x, 20.x
|
|
79
|
+
- Steps:
|
|
80
|
+
- Checkout code
|
|
81
|
+
- Setup Node.js
|
|
82
|
+
- Install dependencies
|
|
83
|
+
- Run linter (if available)
|
|
84
|
+
- Run tests with coverage
|
|
85
|
+
- Upload coverage to Codecov
|
|
86
|
+
|
|
87
|
+
2. **Publish Workflow** (`publish.yml`)
|
|
88
|
+
- Runs on: Release created
|
|
89
|
+
- Platforms: Ubuntu
|
|
90
|
+
- Steps:
|
|
91
|
+
- Checkout code
|
|
92
|
+
- Setup Node.js
|
|
93
|
+
- Install dependencies
|
|
94
|
+
- Run tests
|
|
95
|
+
- Publish to NPM
|
|
96
|
+
|
|
97
|
+
3. **Test Report Workflow** (`test-report.yml`)
|
|
98
|
+
- Runs on: Push, Pull Request, Daily schedule
|
|
99
|
+
- Generates detailed test reports
|
|
100
|
+
- Comments on PRs with test results
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Quality Gates
|
|
105
|
+
|
|
106
|
+
| Gate | Threshold | Current | Status |
|
|
107
|
+
|------|-----------|---------|--------|
|
|
108
|
+
| **Statement Coverage** | 55% | 75.11% | ✅ Pass |
|
|
109
|
+
| **Branch Coverage** | 50% | 54.73% | ✅ Pass |
|
|
110
|
+
| **Function Coverage** | 55% | 65.71% | ✅ Pass |
|
|
111
|
+
| **Line Coverage** | 55% | 76.27% | ✅ Pass |
|
|
112
|
+
| **Build Success** | Required | ✅ | ✅ Pass |
|
|
113
|
+
| **All Tests Pass** | Required | ✅ | ✅ Pass |
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Recent Activity
|
|
118
|
+
|
|
119
|
+
**Last Updated:** Check [GitHub Actions](https://github.com/shahidullahkhankhattak/ssh-keyman/actions) for real-time status
|
|
120
|
+
|
|
121
|
+
**Test History:** All tests passing consistently across all platforms
|
|
122
|
+
|
|
123
|
+
**Coverage Trend:** Maintaining 75%+ coverage
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Quick Links
|
|
128
|
+
|
|
129
|
+
- 📊 [Full Test Report](https://github.com/shahidullahkhankhattak/ssh-keyman/actions/workflows/ci.yml)
|
|
130
|
+
- 📈 [Coverage Dashboard](https://codecov.io/gh/shahidullahkhankhattak/ssh-keyman)
|
|
131
|
+
- 🐛 [Open Issues](https://github.com/shahidullahkhankhattak/ssh-keyman/issues)
|
|
132
|
+
- 🔀 [Pull Requests](https://github.com/shahidullahkhankhattak/ssh-keyman/pulls)
|
|
133
|
+
- 📦 [NPM Package](https://www.npmjs.com/package/ssh-keyman)
|
|
134
|
+
|
package/codecov.yml
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
codecov:
|
|
2
|
+
require_ci_to_pass: yes
|
|
3
|
+
|
|
4
|
+
coverage:
|
|
5
|
+
precision: 2
|
|
6
|
+
round: down
|
|
7
|
+
range: "50...100"
|
|
8
|
+
|
|
9
|
+
status:
|
|
10
|
+
project:
|
|
11
|
+
default:
|
|
12
|
+
target: 55%
|
|
13
|
+
threshold: 5%
|
|
14
|
+
base: auto
|
|
15
|
+
patch:
|
|
16
|
+
default:
|
|
17
|
+
target: 50%
|
|
18
|
+
threshold: 5%
|
|
19
|
+
|
|
20
|
+
comment:
|
|
21
|
+
layout: "reach,diff,flags,tree"
|
|
22
|
+
behavior: default
|
|
23
|
+
require_changes: false
|
|
24
|
+
|
|
25
|
+
ignore:
|
|
26
|
+
- "src/__tests__"
|
|
27
|
+
- "**/*.test.js"
|
|
28
|
+
- "**/node_modules/**"
|
|
29
|
+
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ssh-keyman",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A cli tool to manage multiple ssh keys and switch between different ssh keys with ease & grace.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": "index.js",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "
|
|
8
|
+
"test": "jest --coverage",
|
|
9
|
+
"test:watch": "jest --watch",
|
|
10
|
+
"test:ci": "jest --coverage --ci --maxWorkers=2"
|
|
9
11
|
},
|
|
10
12
|
"repository": {
|
|
11
13
|
"type": "git",
|
|
@@ -34,6 +36,35 @@
|
|
|
34
36
|
},
|
|
35
37
|
"homepage": "https://github.com/shahidullahkhankhattak/ssh-keyman#readme",
|
|
36
38
|
"dependencies": {
|
|
37
|
-
"
|
|
39
|
+
"chalk": "^4.1.2",
|
|
40
|
+
"fs-extra": "^10.0.0",
|
|
41
|
+
"inquirer": "^8.2.5",
|
|
42
|
+
"inquirer-autocomplete-prompt": "^2.0.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"jest": "^29.7.0",
|
|
46
|
+
"@types/jest": "^29.5.11"
|
|
47
|
+
},
|
|
48
|
+
"jest": {
|
|
49
|
+
"testEnvironment": "node",
|
|
50
|
+
"coverageDirectory": "coverage",
|
|
51
|
+
"collectCoverageFrom": [
|
|
52
|
+
"src/**/*.js",
|
|
53
|
+
"!src/**/*.test.js",
|
|
54
|
+
"!src/__tests__/helpers.js",
|
|
55
|
+
"!**/node_modules/**"
|
|
56
|
+
],
|
|
57
|
+
"testMatch": [
|
|
58
|
+
"**/__tests__/**/*.test.js",
|
|
59
|
+
"**/?(*.)+(spec|test).js"
|
|
60
|
+
],
|
|
61
|
+
"coverageThreshold": {
|
|
62
|
+
"global": {
|
|
63
|
+
"branches": 50,
|
|
64
|
+
"functions": 55,
|
|
65
|
+
"lines": 55,
|
|
66
|
+
"statements": 55
|
|
67
|
+
}
|
|
68
|
+
}
|
|
38
69
|
}
|
|
39
70
|
}
|
package/readme.md
CHANGED
|
@@ -1,9 +1,51 @@
|
|
|
1
1
|
ssh-keyman
|
|
2
2
|
=====
|
|
3
3
|
|
|
4
|
+
<!-- Build & Test Status -->
|
|
5
|
+
[](https://github.com/shahidullahkhankhattak/ssh-keyman/actions/workflows/ci.yml)
|
|
6
|
+
[](https://github.com/shahidullahkhankhattak/ssh-keyman/actions/workflows/ci.yml)
|
|
7
|
+
[](https://codecov.io/gh/shahidullahkhankhattak/ssh-keyman)
|
|
8
|
+
[](https://codecov.io/gh/shahidullahkhankhattak/ssh-keyman)
|
|
9
|
+
|
|
10
|
+
<!-- Package Info -->
|
|
11
|
+
[](https://www.npmjs.com/package/ssh-keyman)
|
|
12
|
+
[](https://www.npmjs.com/package/ssh-keyman)
|
|
13
|
+
[](https://bundlephobia.com/package/ssh-keyman)
|
|
14
|
+
|
|
15
|
+
<!-- Platform & Standards -->
|
|
16
|
+
[](https://nodejs.org/)
|
|
17
|
+
[](https://opensource.org/licenses/ISC)
|
|
18
|
+
[](https://github.com/shahidullahkhankhattak/ssh-keyman/graphs/commit-activity)
|
|
19
|
+
[](CONTRIBUTING.md)
|
|
20
|
+
|
|
21
|
+
<!-- Repository Stats -->
|
|
22
|
+
[](https://github.com/shahidullahkhankhattak/ssh-keyman/commits)
|
|
23
|
+
[](https://github.com/shahidullahkhankhattak/ssh-keyman/issues)
|
|
24
|
+
[](https://github.com/shahidullahkhankhattak/ssh-keyman/pulls)
|
|
25
|
+
[](https://github.com/shahidullahkhankhattak/ssh-keyman/stargazers)
|
|
26
|
+
|
|
4
27
|
A sophisticated key manager cli tool to manage multiple ssh keys and switch between different ssh keys with ease & grace.
|
|
5
28
|
|
|
6
|
-
|
|
29
|
+
## CI/CD Status
|
|
30
|
+
|
|
31
|
+
| Workflow | Status |
|
|
32
|
+
|----------|--------|
|
|
33
|
+
| **Build & Test** | [](https://github.com/shahidullahkhankhattak/ssh-keyman/actions/workflows/ci.yml) |
|
|
34
|
+
| **NPM Publish** | [](https://github.com/shahidullahkhankhattak/ssh-keyman/actions/workflows/publish.yml) |
|
|
35
|
+
| **Test Coverage** |  |
|
|
36
|
+
|
|
37
|
+
> 📊 **[View Detailed Status Report →](STATUS.md)**
|
|
38
|
+
|
|
39
|
+
### Platform Support
|
|
40
|
+
|
|
41
|
+
Tests run automatically on:
|
|
42
|
+
- ✅ **Ubuntu** (Linux) - Node.js 16.x, 18.x, 20.x
|
|
43
|
+
- ✅ **macOS** - Node.js 16.x, 18.x, 20.x
|
|
44
|
+
- ✅ **Windows** - Node.js 16.x, 18.x, 20.x
|
|
45
|
+
|
|
46
|
+
**35 Tests** | **75%+ Coverage** | **All Platforms Passing**
|
|
47
|
+
|
|
48
|
+
## Overview
|
|
7
49
|
--------
|
|
8
50
|
|
|
9
51
|
Normally people have difficulty managing different ssh keys for different Github / Bitbucket / Gitlab accounts. This package makes your life easier by creating different ssh profiles & manage them for you. So you can concentrate on your work.
|
|
@@ -22,38 +64,64 @@ Usage
|
|
|
22
64
|
```
|
|
23
65
|
➜ ~ ssh-keyman -h
|
|
24
66
|
|
|
25
|
-
|
|
26
|
-
|
|
67
|
+
SSH KeyMan - SSH Key Environment Manager
|
|
68
|
+
|
|
69
|
+
Usage: ssh-keyman <command> [options]
|
|
27
70
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
71
|
+
Commands:
|
|
72
|
+
-i Initialize keyman directory and default environment
|
|
73
|
+
-c [name] Create new ssh environment (interactive if no name)
|
|
74
|
+
-s [name] Switch to another ssh environment (interactive if no name)
|
|
75
|
+
-d [name] Delete ssh environment (interactive if no name)
|
|
76
|
+
-ls List all environments
|
|
77
|
+
-h Show help
|
|
78
|
+
-v Show version
|
|
79
|
+
|
|
80
|
+
Tip: Run commands without arguments for interactive mode
|
|
36
81
|
```
|
|
37
82
|
|
|
83
|
+
### ✨ New Interactive Features
|
|
84
|
+
|
|
85
|
+
ssh-keyman now supports **interactive mode with autocomplete**! Simply run commands without arguments to get an enhanced interactive experience:
|
|
86
|
+
|
|
87
|
+
- **`ssh-keyman -s`** - Interactive environment switcher with autocomplete
|
|
88
|
+
- **`ssh-keyman -c`** - Interactive environment creator with validation
|
|
89
|
+
- **`ssh-keyman -d`** - Interactive environment deletion with confirmation
|
|
90
|
+
|
|
38
91
|
#### Initialisation
|
|
39
92
|
|
|
40
93
|
Calling `ssh-keyman -i` creates a `~/.sshkeyman/` directory if it doesn't exist,
|
|
41
94
|
and copies your current `~/.ssh` as the 'default' ssh profile.
|
|
42
95
|
```
|
|
43
96
|
➜ ~ ssh-keyman -i
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
97
|
+
|
|
98
|
+
🔑 Initializing SSH KeyMan...
|
|
99
|
+
|
|
100
|
+
✓ Created ssh-keyman directory: /Users/shahidullahkhan/.sshkeyman
|
|
101
|
+
✓ Created default environment
|
|
102
|
+
✓ Activated 'default' environment
|
|
103
|
+
|
|
104
|
+
✨ SSH KeyMan initialized successfully!
|
|
47
105
|
```
|
|
48
106
|
|
|
49
107
|
#### Create a new ssh environment
|
|
50
108
|
|
|
109
|
+
With environment name:
|
|
51
110
|
```
|
|
52
111
|
➜ ~ ssh-keyman -c newenvironment
|
|
53
|
-
Saved current ssh config to
|
|
54
|
-
Created directory for new environment
|
|
55
|
-
Do you want to switch to newly created environment (newenvironment)? y
|
|
56
|
-
Activated environment 'newenvironment'
|
|
112
|
+
✓ Saved current ssh config to default
|
|
113
|
+
✓ Created directory for new environment: /Users/shahidullahkhan/.sshkeyman/newenvironment
|
|
114
|
+
? Do you want to switch to newly created environment (newenvironment)? (Y/n) y
|
|
115
|
+
✓ Activated environment 'newenvironment'
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Interactive mode** (just run without name):
|
|
119
|
+
```
|
|
120
|
+
➜ ~ ssh-keyman -c
|
|
121
|
+
? Enter name for the new environment: production
|
|
122
|
+
✓ Saved current ssh config to default
|
|
123
|
+
✓ Created directory for new environment: /Users/shahidullahkhan/.sshkeyman/production
|
|
124
|
+
? Do you want to switch to newly created environment (production)? (Y/n)
|
|
57
125
|
```
|
|
58
126
|
|
|
59
127
|
A blank environment will be created. Then modify content of `~/.ssh/`. Then whenever you will switch to another environment, your changes will be saved.
|
|
@@ -61,33 +129,100 @@ A blank environment will be created. Then modify content of `~/.ssh/`. Then when
|
|
|
61
129
|
#### List available ssh environments
|
|
62
130
|
|
|
63
131
|
```
|
|
64
|
-
➜ ~ ssh-keyman ls
|
|
132
|
+
➜ ~ ssh-keyman -ls
|
|
133
|
+
|
|
65
134
|
Available environments:
|
|
66
|
-
default
|
|
67
|
-
|
|
135
|
+
• default
|
|
136
|
+
✓ newenvironment (active)
|
|
68
137
|
```
|
|
69
138
|
|
|
70
139
|
#### Switch to a specific ssh environment
|
|
71
140
|
|
|
141
|
+
With environment name:
|
|
72
142
|
```
|
|
73
143
|
➜ ~ ssh-keyman -s default
|
|
74
|
-
Saved current ssh config to 'newenvironment'
|
|
75
|
-
Activated environment 'default'
|
|
144
|
+
✓ Saved current ssh config to 'newenvironment'
|
|
145
|
+
✓ Activated environment 'default'
|
|
76
146
|
```
|
|
77
147
|
|
|
148
|
+
**Interactive mode with autocomplete** (just run without name):
|
|
149
|
+
```
|
|
150
|
+
➜ ~ ssh-keyman -s
|
|
151
|
+
? Select environment to switch to: (Use arrow keys or type to search)
|
|
152
|
+
❯ default
|
|
153
|
+
production
|
|
154
|
+
staging
|
|
155
|
+
```
|
|
156
|
+
Start typing to filter environments with autocomplete!
|
|
157
|
+
|
|
78
158
|
#### Delete a specific ssh environment
|
|
79
159
|
|
|
160
|
+
With environment name:
|
|
80
161
|
```
|
|
81
162
|
➜ ~ ssh-keyman -d newenvironment
|
|
82
|
-
Successfully deleted environment 'newenvironment'
|
|
163
|
+
✓ Successfully deleted environment 'newenvironment'
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
**Interactive mode with autocomplete and confirmation** (just run without name):
|
|
167
|
+
```
|
|
168
|
+
➜ ~ ssh-keyman -d
|
|
169
|
+
? Select environment to delete: (Use arrow keys or type to search)
|
|
170
|
+
❯ newenvironment
|
|
171
|
+
staging
|
|
172
|
+
? Are you sure you want to delete environment 'newenvironment'? (y/N) y
|
|
173
|
+
✓ Successfully deleted environment 'newenvironment'
|
|
83
174
|
```
|
|
84
175
|
|
|
85
176
|
#### Get the current ssh-keyman version
|
|
86
177
|
|
|
87
178
|
```
|
|
88
179
|
➜ ~ ssh-keyman -v
|
|
89
|
-
|
|
180
|
+
ssh-keyman version 1.0.2
|
|
90
181
|
```
|
|
182
|
+
|
|
183
|
+
Development
|
|
184
|
+
-----------
|
|
185
|
+
|
|
186
|
+
### Running Tests
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# Run all tests
|
|
190
|
+
npm test
|
|
191
|
+
|
|
192
|
+
# Run tests in watch mode
|
|
193
|
+
npm run test:watch
|
|
194
|
+
|
|
195
|
+
# Run tests with coverage
|
|
196
|
+
npm run test:ci
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Project Structure
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
ssh-keyman/
|
|
203
|
+
├── src/
|
|
204
|
+
│ ├── __tests__/ # Test files
|
|
205
|
+
│ ├── cli.js # CLI entry point
|
|
206
|
+
│ ├── cliOptions.js # CLI argument parsing
|
|
207
|
+
│ ├── commands.js # Command implementations
|
|
208
|
+
│ ├── constants.js # Constants and configuration
|
|
209
|
+
│ └── extendFs.js # File system utilities
|
|
210
|
+
├── .github/
|
|
211
|
+
│ └── workflows/ # GitHub Actions CI/CD
|
|
212
|
+
├── index.js # Main entry point
|
|
213
|
+
└── package.json
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Contributing
|
|
217
|
+
|
|
218
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
219
|
+
|
|
220
|
+
1. Fork the repository
|
|
221
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
222
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
223
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
224
|
+
5. Open a Pull Request
|
|
225
|
+
|
|
91
226
|
License
|
|
92
227
|
-------
|
|
93
228
|
ISC, a permissive free software license published by the Internet Software Consortium.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const { prepareArgs, getName, init } = require("../cliOptions");
|
|
2
|
+
const { options } = require("../constants");
|
|
3
|
+
|
|
4
|
+
describe("cliOptions", () => {
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
// Clear options array before each test
|
|
7
|
+
options.length = 0;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe("prepareArgs", () => {
|
|
11
|
+
it("should extract command line arguments starting with dash", () => {
|
|
12
|
+
const argv = ["node", "index.js", "-i", "-c"];
|
|
13
|
+
const args = prepareArgs(argv);
|
|
14
|
+
expect(args).toEqual(["i", "c"]);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("should remove dashes from arguments", () => {
|
|
18
|
+
const argv = ["node", "index.js", "--init", "-c"];
|
|
19
|
+
const args = prepareArgs(argv);
|
|
20
|
+
expect(args).toEqual(["init", "c"]);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("should filter out non-dash arguments", () => {
|
|
24
|
+
const argv = ["node", "index.js", "-s", "production", "-c"];
|
|
25
|
+
const args = prepareArgs(argv);
|
|
26
|
+
expect(args).toEqual(["s", "c"]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should return empty array when no dash arguments", () => {
|
|
30
|
+
const argv = ["node", "index.js", "somename"];
|
|
31
|
+
const args = prepareArgs(argv);
|
|
32
|
+
expect(args).toEqual([]);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("getName", () => {
|
|
37
|
+
it("should extract the first non-dash argument", () => {
|
|
38
|
+
const argv = ["node", "index.js", "-s", "production"];
|
|
39
|
+
const name = getName(argv);
|
|
40
|
+
expect(name).toBe("production");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should return undefined when no non-dash arguments", () => {
|
|
44
|
+
const argv = ["node", "index.js", "-i", "-c"];
|
|
45
|
+
const name = getName(argv);
|
|
46
|
+
expect(name).toBeUndefined();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should return first non-dash argument when multiple exist", () => {
|
|
50
|
+
const argv = ["node", "index.js", "first", "second", "-s"];
|
|
51
|
+
const name = getName(argv);
|
|
52
|
+
expect(name).toBe("first");
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("init", () => {
|
|
57
|
+
it("should populate options array", () => {
|
|
58
|
+
expect(options.length).toBe(0);
|
|
59
|
+
init();
|
|
60
|
+
expect(options.length).toBeGreaterThan(0);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("should create options with correct structure", () => {
|
|
64
|
+
init();
|
|
65
|
+
options.forEach((option) => {
|
|
66
|
+
expect(option).toHaveProperty("option");
|
|
67
|
+
expect(option).toHaveProperty("name");
|
|
68
|
+
expect(option).toHaveProperty("method");
|
|
69
|
+
expect(option).toHaveProperty("help");
|
|
70
|
+
expect(typeof option.option).toBe("string");
|
|
71
|
+
expect(typeof option.name).toBe("string");
|
|
72
|
+
expect(typeof option.method).toBe("string");
|
|
73
|
+
expect(typeof option.help).toBe("string");
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|