samovar 2.4.1 → 2.5.1

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.
data/lib/samovar/split.rb CHANGED
@@ -3,6 +3,8 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2016-2025, by Samuel Williams.
5
5
 
6
+ require_relative "completion"
7
+
6
8
  module Samovar
7
9
  # Represents a split point in the command-line arguments.
8
10
  #
@@ -15,12 +17,14 @@ module Samovar
15
17
  # @parameter marker [String] The marker that indicates the split point.
16
18
  # @parameter default [Object] The default value if no split is present.
17
19
  # @parameter required [Boolean] Whether the split is required.
18
- def initialize(key, description, marker: "--", default: nil, required: false)
20
+ # @parameter completions [Array | Proc | Nil] Completions for split arguments.
21
+ def initialize(key, description, marker: "--", default: nil, required: false, completions: nil)
19
22
  @key = key
20
23
  @description = description
21
24
  @marker = marker
22
25
  @default = default
23
26
  @required = required
27
+ @completions = completions
24
28
  end
25
29
 
26
30
  # The name of the attribute to store the values after the split.
@@ -48,6 +52,11 @@ module Samovar
48
52
  # @attribute [Boolean]
49
53
  attr :required
50
54
 
55
+ # Completions for split arguments.
56
+ #
57
+ # @attribute [Array | Proc | Nil]
58
+ attr :completions
59
+
51
60
  # Generate a string representation for usage output.
52
61
  #
53
62
  # @returns [String] The usage string.
@@ -85,5 +94,40 @@ module Samovar
85
94
  raise MissingValueError.new(parent, @key)
86
95
  end
87
96
  end
97
+
98
+ # Complete the split marker or arguments after it.
99
+ #
100
+ # @parameter input [Array(String)] Previously completed command-line arguments.
101
+ # @parameter context [Completion::Context] The completion context.
102
+ # @parameter collected [Array(Completion::Suggestion)] Suggestions collected so far.
103
+ # @returns [Completion::Result | Nil] A final completion result, or nil to continue.
104
+ def complete(input, context, collected)
105
+ if offset = input.index(@marker)
106
+ input.shift(offset + 1)
107
+
108
+ if @completions == :executable && input.any?
109
+ return Completion::Result.new(collected + [
110
+ Completion::Suggestion.new(
111
+ input.first,
112
+ description: "Delegate completion",
113
+ type: :delegate,
114
+ index: context.arguments.index(@marker) + 1,
115
+ ),
116
+ ])
117
+ end
118
+
119
+ return Completion::Result.new(collected) + Completion::Provider.new(context.with_row(self), @completions).suggestions
120
+ end
121
+
122
+ return Completion::Result.new(collected) unless input.empty?
123
+
124
+ suggestions = []
125
+
126
+ if @marker.start_with?(context.current)
127
+ suggestions << Completion::Suggestion.new(@marker, description: @description, type: :split)
128
+ end
129
+
130
+ return Completion::Result.new(collected + suggestions)
131
+ end
88
132
  end
89
133
  end
@@ -6,5 +6,5 @@
6
6
 
7
7
  # @namespace
8
8
  module Samovar
9
- VERSION = "2.4.1"
9
+ VERSION = "2.5.1"
10
10
  end
data/license.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2016-2025, by Samuel Williams.
3
+ Copyright, 2016-2026, by Samuel Williams.
4
4
  Copyright, 2018, by Gabriel Mazetto.
5
+ Copyright, 2026, by Gerhard Schlager.
5
6
 
6
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
7
8
  of this software and associated documentation files (the "Software"), to deal
data/readme.md CHANGED
@@ -18,11 +18,23 @@ Please see the [project documentation](https://ioquatix.github.io/samovar/) for
18
18
 
19
19
  - [Getting Started](https://ioquatix.github.io/samovar/guides/getting-started/index) - This guide explains how to use `samovar` to build command-line tools and applications.
20
20
 
21
+ - [Completion](https://ioquatix.github.io/samovar/guides/completion/index) - This guide explains how to add shell completion to commands built with `samovar`.
22
+
21
23
  ## Releases
22
24
 
23
25
  Please see the [project releases](https://ioquatix.github.io/samovar/releases/index) for all releases.
24
26
 
25
- ### v2.4.1
27
+ ### v2.5.1
28
+
29
+ - Fix completion of empty arguments.
30
+
31
+ ### v2.5.0
32
+
33
+ - Introduce `Command#complete` which provides a hook for command completion logic, allowing developers to implement custom tab-completion behavior for their commands.
34
+
35
+ ### v2.4.2
36
+
37
+ - Drop dependency on `mapping` gem.
26
38
 
27
39
  ### v2.4.0
28
40
 
@@ -58,6 +70,22 @@ We welcome contributions to this project.
58
70
  4. Push to the branch (`git push origin my-new-feature`).
59
71
  5. Create new Pull Request.
60
72
 
73
+ ### Running Tests
74
+
75
+ To run the test suite:
76
+
77
+ ``` shell
78
+ bundle exec sus
79
+ ```
80
+
81
+ ### Making Releases
82
+
83
+ To make a new release:
84
+
85
+ ``` shell
86
+ bundle exec bake gem:release:patch # or minor or major
87
+ ```
88
+
61
89
  ### Developer Certificate of Origin
62
90
 
63
91
  In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
@@ -66,7 +94,7 @@ In order to protect users of this project, we require all contributors to comply
66
94
 
67
95
  This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
68
96
 
69
- ### Future Work
97
+ ## Future Work
70
98
 
71
99
  ### Multi-value Options
72
100
 
@@ -88,12 +116,6 @@ command list -- --help
88
116
 
89
117
  In this case, do we show help? Some effort is required to disambiguate this. Initially, it makes sense to keep things as simple as possible. But, it might make sense for some options to be declared in a global scope, which are extracted before parsing begins. I'm not sure if this is really a good idea. It might just be better to give good error output in this case (you specified an option but it was in the wrong place).
90
118
 
91
- ### Shell Auto-completion
92
-
93
- Because of the structure of the Samovar command parser, it should be possible to generate a list of all possible tokens at each point. Therefore, semantically correct tab completion should be possible.
94
-
95
- As a secondary to this, it would be nice if `Samovar::One` and `Samovar::Many` could take a list of potential tokens so that auto-completion could give meaningful suggestions, and possibly improved validation.
96
-
97
119
  ### Short/Long Help
98
120
 
99
121
  It might be interesting to explore whether it's possible to have `-h` and `--help` do different things. This could include command specific help output, more detailed help output (similar to a man page), and other useful help related tasks.
data/releases.md CHANGED
@@ -1,6 +1,16 @@
1
1
  # Releases
2
2
 
3
- ## v2.4.1
3
+ ## v2.5.1
4
+
5
+ - Fix completion of empty arguments.
6
+
7
+ ## v2.5.0
8
+
9
+ - Introduce `Command#complete` which provides a hook for command completion logic, allowing developers to implement custom tab-completion behavior for their commands.
10
+
11
+ ## v2.4.2
12
+
13
+ - Drop dependency on `mapping` gem.
4
14
 
5
15
  ## v2.4.0
6
16
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,11 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: samovar
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  - Gabriel Mazetto
9
+ - Gerhard Schlager
9
10
  bindir: bin
10
11
  cert_chain:
11
12
  - |
@@ -53,28 +54,20 @@ dependencies:
53
54
  - - "~>"
54
55
  - !ruby/object:Gem::Version
55
56
  version: '1.0'
56
- - !ruby/object:Gem::Dependency
57
- name: mapping
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '1.0'
63
- type: :runtime
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '1.0'
70
57
  executables: []
71
58
  extensions: []
72
59
  extra_rdoc_files: []
73
60
  files:
61
+ - context/completion.md
74
62
  - context/getting-started.md
75
63
  - context/index.yaml
76
64
  - lib/samovar.rb
77
65
  - lib/samovar/command.rb
66
+ - lib/samovar/completion.rb
67
+ - lib/samovar/completion/context.rb
68
+ - lib/samovar/completion/provider.rb
69
+ - lib/samovar/completion/result.rb
70
+ - lib/samovar/completion/suggestion.rb
78
71
  - lib/samovar/error.rb
79
72
  - lib/samovar/failure.rb
80
73
  - lib/samovar/flags.rb
@@ -109,14 +102,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
102
  requirements:
110
103
  - - ">="
111
104
  - !ruby/object:Gem::Version
112
- version: '3.2'
105
+ version: '3.3'
113
106
  required_rubygems_version: !ruby/object:Gem::Requirement
114
107
  requirements:
115
108
  - - ">="
116
109
  - !ruby/object:Gem::Version
117
110
  version: '0'
118
111
  requirements: []
119
- rubygems_version: 3.6.9
112
+ rubygems_version: 4.0.10
120
113
  specification_version: 4
121
114
  summary: Samovar is a flexible option parser excellent support for sub-commands and
122
115
  help documentation.
metadata.gz.sig CHANGED
Binary file