samovar 2.4.1 → 2.5.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/context/completion.md +206 -0
- data/context/index.yaml +4 -0
- data/lib/samovar/command.rb +24 -9
- data/lib/samovar/completion/context.rb +115 -0
- data/lib/samovar/completion/provider.rb +75 -0
- data/lib/samovar/completion/result.rb +54 -0
- data/lib/samovar/completion/suggestion.rb +94 -0
- data/lib/samovar/completion.rb +24 -0
- data/lib/samovar/failure.rb +1 -1
- data/lib/samovar/flags.rb +32 -0
- data/lib/samovar/many.rb +33 -2
- data/lib/samovar/nested.rb +46 -3
- data/lib/samovar/one.rb +28 -2
- data/lib/samovar/option.rb +63 -5
- data/lib/samovar/options.rb +90 -6
- data/lib/samovar/output/columns.rb +1 -1
- data/lib/samovar/output/header.rb +1 -1
- data/lib/samovar/output/usage_formatter.rb +41 -35
- data/lib/samovar/split.rb +45 -1
- data/lib/samovar/version.rb +1 -1
- data/license.md +2 -1
- data/readme.md +26 -8
- data/releases.md +7 -1
- data.tar.gz.sig +0 -0
- metadata +10 -17
- metadata.gz.sig +0 -0
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
|
-
|
|
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.words.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
|
data/lib/samovar/version.rb
CHANGED
data/license.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# MIT License
|
|
2
2
|
|
|
3
|
-
Copyright, 2016-
|
|
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,19 @@ 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.
|
|
27
|
+
### v2.5.0
|
|
28
|
+
|
|
29
|
+
- Introduce `Command#complete` which provides a hook for command completion logic, allowing developers to implement custom tab-completion behavior for their commands.
|
|
30
|
+
|
|
31
|
+
### v2.4.2
|
|
32
|
+
|
|
33
|
+
- Drop dependency on `mapping` gem.
|
|
26
34
|
|
|
27
35
|
### v2.4.0
|
|
28
36
|
|
|
@@ -58,6 +66,22 @@ We welcome contributions to this project.
|
|
|
58
66
|
4. Push to the branch (`git push origin my-new-feature`).
|
|
59
67
|
5. Create new Pull Request.
|
|
60
68
|
|
|
69
|
+
### Running Tests
|
|
70
|
+
|
|
71
|
+
To run the test suite:
|
|
72
|
+
|
|
73
|
+
``` shell
|
|
74
|
+
bundle exec sus
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Making Releases
|
|
78
|
+
|
|
79
|
+
To make a new release:
|
|
80
|
+
|
|
81
|
+
``` shell
|
|
82
|
+
bundle exec bake gem:release:patch # or minor or major
|
|
83
|
+
```
|
|
84
|
+
|
|
61
85
|
### Developer Certificate of Origin
|
|
62
86
|
|
|
63
87
|
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 +90,7 @@ In order to protect users of this project, we require all contributors to comply
|
|
|
66
90
|
|
|
67
91
|
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
92
|
|
|
69
|
-
|
|
93
|
+
## Future Work
|
|
70
94
|
|
|
71
95
|
### Multi-value Options
|
|
72
96
|
|
|
@@ -88,12 +112,6 @@ command list -- --help
|
|
|
88
112
|
|
|
89
113
|
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
114
|
|
|
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
115
|
### Short/Long Help
|
|
98
116
|
|
|
99
117
|
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,12 @@
|
|
|
1
1
|
# Releases
|
|
2
2
|
|
|
3
|
-
## v2.
|
|
3
|
+
## v2.5.0
|
|
4
|
+
|
|
5
|
+
- Introduce `Command#complete` which provides a hook for command completion logic, allowing developers to implement custom tab-completion behavior for their commands.
|
|
6
|
+
|
|
7
|
+
## v2.4.2
|
|
8
|
+
|
|
9
|
+
- Drop dependency on `mapping` gem.
|
|
4
10
|
|
|
5
11
|
## v2.4.0
|
|
6
12
|
|
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
|
+
version: 2.5.0
|
|
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.
|
|
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:
|
|
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
|