jarvy 0.0.5

Jarvy is a fast, cross-platform CLI that installs and manages developer tools across macOS and Linux.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
//! CI configuration file generation
//!
//! Generates CI workflow/pipeline configuration files for various providers.

use super::CiProvider;
use std::fmt;
use std::io::Write;
use std::path::Path;

/// Error type for CI config generation
#[derive(Debug)]
pub enum CiConfigError {
    /// IO error when writing config file
    IoError(std::io::Error),
    /// Unsupported provider for config generation
    #[allow(dead_code)] // Returned by generate_ci_config which is public API
    UnsupportedProvider(CiProvider),
}

impl fmt::Display for CiConfigError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::IoError(e) => write!(f, "IO error: {}", e),
            Self::UnsupportedProvider(p) => {
                write!(f, "Config generation not supported for {}", p)
            }
        }
    }
}

impl std::error::Error for CiConfigError {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Self::IoError(e) => Some(e),
            Self::UnsupportedProvider(_) => None,
        }
    }
}

impl From<std::io::Error> for CiConfigError {
    fn from(e: std::io::Error) -> Self {
        Self::IoError(e)
    }
}

/// CI config template for a specific provider
pub struct CiConfigTemplate {
    /// The CI provider
    pub provider: CiProvider,
    /// Template content
    pub content: String,
    /// Suggested file path
    pub file_path: &'static str,
    /// Description of the template
    pub description: &'static str,
}

impl CiConfigTemplate {
    /// Returns the template for the given provider
    pub fn for_provider(provider: CiProvider) -> Option<Self> {
        match provider {
            CiProvider::GitHubActions => Some(Self::github_actions()),
            CiProvider::GitLabCi => Some(Self::gitlab_ci()),
            CiProvider::CircleCi => Some(Self::circleci()),
            CiProvider::AzureDevOps => Some(Self::azure_devops()),
            CiProvider::Bitbucket => Some(Self::bitbucket()),
            _ => None,
        }
    }

    fn github_actions() -> Self {
        Self {
            provider: CiProvider::GitHubActions,
            file_path: ".github/workflows/jarvy.yml",
            description: "GitHub Actions workflow for Jarvy setup",
            content: r#"# Jarvy Development Environment Setup
# This workflow provisions development tools using Jarvy

name: Jarvy Setup

on:
  push:
    branches: [main, master]
    paths:
      - 'jarvy.toml'
  pull_request:
    branches: [main, master]
    paths:
      - 'jarvy.toml'
  workflow_dispatch:

jobs:
  setup:
    name: Provision Environment
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Cache Homebrew packages
        uses: actions/cache@v4
        with:
          path: |
            ~/Library/Caches/Homebrew
            /usr/local/Cellar
          key: ${{ runner.os }}-brew-${{ hashFiles('jarvy.toml') }}
          restore-keys: |
            ${{ runner.os }}-brew-

      - name: Install Jarvy
        run: |
          # Install Jarvy (update with actual installation method)
          cargo install jarvy || curl -fsSL https://get.jarvy.dev | bash

      - name: Run Jarvy Setup
        run: jarvy setup --file jarvy.toml

      - name: Verify Installation
        run: jarvy get --format json

  # Optional: Run on multiple platforms
  setup-matrix:
    name: Setup (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    if: github.event_name == 'workflow_dispatch'
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
      fail-fast: false

    steps:
      - uses: actions/checkout@v4

      - name: Install Jarvy
        run: cargo install jarvy || curl -fsSL https://get.jarvy.dev | bash

      - name: Run Jarvy Setup
        run: jarvy setup --file jarvy.toml
"#
            .to_string(),
        }
    }

    fn gitlab_ci() -> Self {
        Self {
            provider: CiProvider::GitLabCi,
            file_path: ".gitlab-ci.yml",
            description: "GitLab CI configuration for Jarvy setup",
            content: r#"# Jarvy Development Environment Setup
# This pipeline provisions development tools using Jarvy

stages:
  - setup
  - verify

variables:
  # Cache configuration
  JARVY_CACHE_DIR: /cache/jarvy

.jarvy-base:
  cache:
    key: jarvy-$CI_COMMIT_REF_SLUG
    paths:
      - /cache/jarvy
      - ~/.local/share/jarvy
    policy: pull-push

jarvy-setup:
  extends: .jarvy-base
  stage: setup
  image: rust:latest
  script:
    - cargo install jarvy || curl -fsSL https://get.jarvy.dev | bash
    - jarvy setup --file jarvy.toml
  rules:
    - changes:
        - jarvy.toml
      when: always
    - when: manual

jarvy-verify:
  extends: .jarvy-base
  stage: verify
  image: rust:latest
  script:
    - cargo install jarvy || curl -fsSL https://get.jarvy.dev | bash
    - jarvy get --format json
  needs:
    - jarvy-setup
  rules:
    - changes:
        - jarvy.toml
      when: always
    - when: manual

# Multi-platform setup (optional)
.setup-template:
  extends: .jarvy-base
  stage: setup
  script:
    - cargo install jarvy
    - jarvy setup --file jarvy.toml

setup-linux:
  extends: .setup-template
  image: rust:latest
  tags:
    - linux
  when: manual

setup-macos:
  extends: .setup-template
  tags:
    - macos
  when: manual
"#
            .to_string(),
        }
    }

    fn circleci() -> Self {
        Self {
            provider: CiProvider::CircleCi,
            file_path: ".circleci/config.yml",
            description: "CircleCI configuration for Jarvy setup",
            content: r#"# Jarvy Development Environment Setup
# This workflow provisions development tools using Jarvy

version: 2.1

orbs:
  rust: circleci/rust@1.6

executors:
  linux:
    docker:
      - image: cimg/rust:1.75
  macos:
    macos:
      xcode: "15.0"

commands:
  install-jarvy:
    description: "Install Jarvy CLI"
    steps:
      - run:
          name: Install Jarvy
          command: |
            cargo install jarvy || curl -fsSL https://get.jarvy.dev | bash

  run-jarvy-setup:
    description: "Run Jarvy setup"
    steps:
      - run:
          name: Run Jarvy Setup
          command: jarvy setup --file jarvy.toml

jobs:
  setup-linux:
    executor: linux
    steps:
      - checkout
      - restore_cache:
          keys:
            - jarvy-linux-{{ checksum "jarvy.toml" }}
            - jarvy-linux-
      - install-jarvy
      - run-jarvy-setup
      - save_cache:
          key: jarvy-linux-{{ checksum "jarvy.toml" }}
          paths:
            - ~/.cargo
            - ~/.local/share/jarvy
      - run:
          name: Verify Installation
          command: jarvy get --format json

  setup-macos:
    executor: macos
    steps:
      - checkout
      - restore_cache:
          keys:
            - jarvy-macos-{{ checksum "jarvy.toml" }}
            - jarvy-macos-
      - install-jarvy
      - run-jarvy-setup
      - save_cache:
          key: jarvy-macos-{{ checksum "jarvy.toml" }}
          paths:
            - ~/.cargo
            - ~/Library/Caches/Homebrew
      - run:
          name: Verify Installation
          command: jarvy get --format json

workflows:
  jarvy-setup:
    jobs:
      - setup-linux:
          filters:
            branches:
              only:
                - main
                - master
      - setup-macos:
          filters:
            branches:
              only:
                - main
                - master
"#
            .to_string(),
        }
    }

    fn azure_devops() -> Self {
        Self {
            provider: CiProvider::AzureDevOps,
            file_path: "azure-pipelines.yml",
            description: "Azure DevOps pipeline for Jarvy setup",
            content: r#"# Jarvy Development Environment Setup
# This pipeline provisions development tools using Jarvy

trigger:
  branches:
    include:
      - main
      - master
  paths:
    include:
      - jarvy.toml

pr:
  branches:
    include:
      - main
      - master
  paths:
    include:
      - jarvy.toml

variables:
  CARGO_HOME: $(Pipeline.Workspace)/.cargo

stages:
  - stage: Setup
    displayName: 'Jarvy Setup'
    jobs:
      - job: Linux
        displayName: 'Linux Setup'
        pool:
          vmImage: 'ubuntu-latest'
        steps:
          - task: Cache@2
            displayName: 'Cache Cargo'
            inputs:
              key: 'cargo | "$(Agent.OS)" | jarvy.toml'
              path: $(CARGO_HOME)
              restoreKeys: |
                cargo | "$(Agent.OS)"

          - script: |
              cargo install jarvy || curl -fsSL https://get.jarvy.dev | bash
            displayName: 'Install Jarvy'

          - script: |
              jarvy setup --file jarvy.toml
            displayName: 'Run Jarvy Setup'

          - script: |
              jarvy get --format json
            displayName: 'Verify Installation'

      - job: macOS
        displayName: 'macOS Setup'
        pool:
          vmImage: 'macos-latest'
        steps:
          - task: Cache@2
            displayName: 'Cache Cargo'
            inputs:
              key: 'cargo | "$(Agent.OS)" | jarvy.toml'
              path: $(CARGO_HOME)
              restoreKeys: |
                cargo | "$(Agent.OS)"

          - script: |
              cargo install jarvy || curl -fsSL https://get.jarvy.dev | bash
            displayName: 'Install Jarvy'

          - script: |
              jarvy setup --file jarvy.toml
            displayName: 'Run Jarvy Setup'

          - script: |
              jarvy get --format json
            displayName: 'Verify Installation'
"#
            .to_string(),
        }
    }

    fn bitbucket() -> Self {
        Self {
            provider: CiProvider::Bitbucket,
            file_path: "bitbucket-pipelines.yml",
            description: "Bitbucket Pipelines configuration for Jarvy setup",
            content: r#"# Jarvy Development Environment Setup
# This pipeline provisions development tools using Jarvy

image: rust:latest

definitions:
  caches:
    cargo: ~/.cargo
    jarvy: ~/.local/share/jarvy

  steps:
    - step: &install-jarvy
        name: Install Jarvy
        script:
          - cargo install jarvy || curl -fsSL https://get.jarvy.dev | bash

    - step: &jarvy-setup
        name: Run Jarvy Setup
        caches:
          - cargo
          - jarvy
        script:
          - cargo install jarvy || curl -fsSL https://get.jarvy.dev | bash
          - jarvy setup --file jarvy.toml
          - jarvy get --format json

pipelines:
  default:
    - step: *jarvy-setup

  branches:
    main:
      - step: *jarvy-setup
    master:
      - step: *jarvy-setup

  pull-requests:
    '**':
      - step: *jarvy-setup

  custom:
    full-setup:
      - step:
          name: Setup (Linux)
          image: rust:latest
          caches:
            - cargo
          script:
            - cargo install jarvy
            - jarvy setup --file jarvy.toml
"#
            .to_string(),
        }
    }

    /// Writes the template to the appropriate file
    pub fn write(&self, base_path: &Path) -> Result<std::path::PathBuf, CiConfigError> {
        let full_path = base_path.join(self.file_path);

        // Create parent directories if needed
        if let Some(parent) = full_path.parent() {
            std::fs::create_dir_all(parent)?;
        }

        let mut file = std::fs::File::create(&full_path)?;
        file.write_all(self.content.as_bytes())?;

        Ok(full_path)
    }
}

/// Generates CI config for the specified provider
#[allow(dead_code)] // Public API for library consumers
pub fn generate_ci_config(
    provider: CiProvider,
    base_path: &Path,
) -> Result<std::path::PathBuf, CiConfigError> {
    let template = CiConfigTemplate::for_provider(provider)
        .ok_or(CiConfigError::UnsupportedProvider(provider))?;

    template.write(base_path)
}

/// Returns a list of providers that support config generation
#[allow(dead_code)] // Public API for library consumers
pub fn supported_providers() -> Vec<CiProvider> {
    vec![
        CiProvider::GitHubActions,
        CiProvider::GitLabCi,
        CiProvider::CircleCi,
        CiProvider::AzureDevOps,
        CiProvider::Bitbucket,
    ]
}

#[cfg(test)]
mod tests {
    use super::*;
    use tempfile::TempDir;

    #[test]
    fn test_github_actions_template() {
        let template = CiConfigTemplate::for_provider(CiProvider::GitHubActions);
        assert!(template.is_some());
        let template = template.unwrap();
        assert_eq!(template.file_path, ".github/workflows/jarvy.yml");
        assert!(template.content.contains("actions/checkout"));
        assert!(template.content.contains("jarvy setup"));
    }

    #[test]
    fn test_gitlab_ci_template() {
        let template = CiConfigTemplate::for_provider(CiProvider::GitLabCi);
        assert!(template.is_some());
        let template = template.unwrap();
        assert_eq!(template.file_path, ".gitlab-ci.yml");
        assert!(template.content.contains("jarvy-setup"));
        assert!(template.content.contains("stages:"));
    }

    #[test]
    fn test_unsupported_provider() {
        let template = CiConfigTemplate::for_provider(CiProvider::Jenkins);
        assert!(template.is_none());
    }

    #[test]
    fn test_write_template() {
        let temp_dir = TempDir::new().unwrap();
        let result = generate_ci_config(CiProvider::GitHubActions, temp_dir.path());
        assert!(result.is_ok());

        let path = result.unwrap();
        assert!(path.exists());
        assert!(path.ends_with(".github/workflows/jarvy.yml"));
    }

    #[test]
    fn test_supported_providers() {
        let providers = supported_providers();
        assert!(!providers.is_empty());
        assert!(providers.contains(&CiProvider::GitHubActions));
        assert!(providers.contains(&CiProvider::GitLabCi));
    }
}