Skip to content

Commit c87db67

Browse files
authored
feat: type: mise_use implementation (#4)
* docs: Update rdoc * doc: Update badge and description * feat: Add `type: mise_use` ``` - type: mise_use name: go - type: mise_use name: ruby version: 3.4.3 ``` * ci: CI against Ruby 3.4 * WIP: Adding global option * docs: `mise_use` * docs: Update placeholder text
2 parents e0640f6 + 74057b9 commit c87db67

File tree

5 files changed

+85
-11
lines changed

5 files changed

+85
-11
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
strategy:
77
matrix:
88
os: [ubuntu-latest, macos-latest]
9-
ruby: ["3.1", "3.2", "3.3", "3.3"]
9+
ruby: ["3.1", "3.2", "3.3", "3.4"]
1010
runs-on: ${{ matrix.os }}
1111
steps:
1212
- uses: actions/checkout@v4

README.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
[![Ruby](https://github.com/serverkit/serverkit-mise/actions/workflows/main.yml/badge.svg)](https://github.com/serverkit/serverkit-mise/actions/workflows/main.yml)
1+
[![Test](https://github.com/serverkit/serverkit-mise/actions/workflows/test.yml/badge.svg)](https://github.com/serverkit/serverkit-mise/actions/workflows/test.yml)
22

3-
# Serverkit::Mise
3+
# serverkit-mise
44

5-
TODO: Delete this and the text below, and describe your gem
6-
7-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/serverkit/mise`. To experiment with that code, run `bin/console` for an interactive prompt.
5+
[Serverkit](https://github.com/serverkit/serverkit) plug-in for [mise](https://github.com/jdx/mise).
86

97
## Installation
108

11-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
9+
TODO: Replace `serverkit-mise` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
1210

1311
Install the gem and add to the application's Gemfile by executing:
1412

1513
```bash
16-
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14+
bundle add serverkit-mise
1715
```
1816

1917
If bundler is not being used to manage dependencies, install the gem by executing:
2018

2119
```bash
22-
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
20+
gem install serverkit-mise
2321
```
2422

2523
## Usage
@@ -48,9 +46,29 @@ resources:
4846
version: 3.4.3
4947
```
5048
49+
### mise_use
50+
51+
Install specified tool and add the version to `mise.yml`.
52+
53+
#### Attributes
54+
55+
- `name` - tool name (required)
56+
- `version` - tool version (optional)
57+
58+
#### Example
59+
60+
```yaml
61+
resources:
62+
- type: mise_use
63+
name: go
64+
version: '1.23'
65+
- type: mise_use
66+
name: ruby
67+
```
68+
5169
## Contributing
5270

53-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/serverkit-mise.
71+
Bug reports and pull requests are welcome on GitHub at [serverkit/serverkit-mise](https://github.com/serverkit/serverkit-mise).
5472

5573
## License
5674

lib/serverkit/mise.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
require_relative "mise/version"
44
require_relative "resources/mise_install"
5+
require_relative "resources/mise_use"

lib/serverkit/resources/mise_install.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def default_id
2626
end
2727

2828
# @return [String]
29-
# @example "git-plus@4.4.11"
29+
# @example "ruby@3.4.3"
3030
def name_with_version
3131
if version
3232
"#{name}@#{version}"
@@ -35,6 +35,7 @@ def name_with_version
3535
end
3636
end
3737

38+
# @return [String]
3839
def version_or_latest
3940
version || "latest"
4041
end
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# frozen_string_literal: true
2+
3+
require "serverkit/resources/base"
4+
5+
module Serverkit
6+
module Resources
7+
class MiseUse < Base
8+
attribute :name, required: true, type: String
9+
attribute :version, type: String
10+
# FIXME: add global option
11+
attribute :global, type: [TrueClass, FalseClass] # , default: true
12+
13+
# @note Override
14+
def apply
15+
run_command("mise use --global #{name_with_version}")
16+
end
17+
18+
# @note Override
19+
def check
20+
cmd = if global
21+
"mise ls --global #{name} | grep '#{version_or_latest}'"
22+
else
23+
"mise ls --current #{name} | grep '#{version_or_latest}'"
24+
end
25+
check_command(cmd)
26+
end
27+
28+
private
29+
30+
# @note Override
31+
def default_id
32+
name
33+
end
34+
35+
# @return [String]
36+
# @example "[email protected]"
37+
def name_with_version
38+
if version
39+
"#{name}@#{version}"
40+
else
41+
name
42+
end
43+
end
44+
45+
def version_or_latest
46+
version || "latest"
47+
end
48+
49+
# def global_option
50+
# "--global" if global
51+
# end
52+
end
53+
end
54+
end

0 commit comments

Comments
 (0)