-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CP-1794 Add completions.dart support #151
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0d5628f
Add initial completions.dart support.
georgelesica-wf 28aba09
Initial consumption of completions.dart.
georgelesica-wf 322e270
Update completions script.
georgelesica-wf 2cc8a05
Update completions and add comment.
georgelesica-wf 2e7e4c6
Remove dart_dev completions because they do not work.
georgelesica-wf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# | ||
# Installation: | ||
# | ||
# Via shell config file ~/.bashrc (or ~/.zshrc) | ||
# | ||
# Append the contents to config file | ||
# 'source' the file in the config file | ||
# | ||
# You may also have a directory on your system that is configured | ||
# for completion files, such as: | ||
# | ||
# /usr/local/etc/bash_completion.d/ | ||
# | ||
|
||
###-begin-ddev-completion-### | ||
|
||
if type complete &>/dev/null; then | ||
__ddev_completion() { | ||
local si="$IFS" | ||
IFS=$'\n' COMPREPLY=($(COMP_CWORD="$COMP_CWORD" \ | ||
COMP_LINE="$COMP_LINE" \ | ||
COMP_POINT="$COMP_POINT" \ | ||
ddev completion -- "${COMP_WORDS[@]}" \ | ||
2>/dev/null)) || return $? | ||
IFS="$si" | ||
} | ||
complete -F __ddev_completion ddev | ||
elif type compdef &>/dev/null; then | ||
__ddev_completion() { | ||
si=$IFS | ||
compadd -- $(COMP_CWORD=$((CURRENT-1)) \ | ||
COMP_LINE=$BUFFER \ | ||
COMP_POINT=0 \ | ||
ddev completion -- "${words[@]}" \ | ||
2>/dev/null) | ||
IFS=$si | ||
} | ||
compdef __ddev_completion ddev | ||
elif type compctl &>/dev/null; then | ||
__ddev_completion() { | ||
local cword line point words si | ||
read -Ac words | ||
read -cn cword | ||
let cword-=1 | ||
read -l line | ||
read -ln point | ||
si="$IFS" | ||
IFS=$'\n' reply=($(COMP_CWORD="$cword" \ | ||
COMP_LINE="$line" \ | ||
COMP_POINT="$point" \ | ||
ddev completion -- "${words[@]}" \ | ||
2>/dev/null)) || return $? | ||
IFS="$si" | ||
} | ||
compctl -K __ddev_completion ddev | ||
fi | ||
|
||
###-end-ddev-completion-### | ||
|
||
## Generated 2016-05-17 19:21:47.711257Z | ||
## By /Volumes/Workspace/dart_dev/.pub/bin/completion/shell_completion_generator.dart.snapshot | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2015 Workiva Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import 'dart:async'; | ||
import 'dart:convert'; | ||
|
||
import 'package:resource/resource.dart' as resource; | ||
|
||
import 'package:dart_dev/src/tasks/task.dart'; | ||
|
||
BashCompletionTask bashCompletion() { | ||
Completer done = new Completer(); | ||
BashCompletionTask task = new BashCompletionTask(done.future); | ||
|
||
var script = new resource.Resource('package:dart_dev/bash-completion.sh'); | ||
script.readAsString(encoding: UTF8).then((content) { | ||
task | ||
..completionScript = content | ||
..successful = true; | ||
done.complete(); | ||
}).catchError((error) { | ||
done.complete(); | ||
}); | ||
|
||
return task; | ||
} | ||
|
||
class BashCompletionTask extends Task { | ||
final Future done; | ||
String completionScript; | ||
BashCompletionTask(Future this.done); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2015 Workiva Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:args/args.dart'; | ||
|
||
import 'package:dart_dev/src/tasks/bash_completion/api.dart'; | ||
import 'package:dart_dev/src/tasks/cli.dart'; | ||
import 'package:dart_dev/util.dart' show reporter; | ||
|
||
class BashCompletionCli extends TaskCli { | ||
final ArgParser argParser = new ArgParser(); | ||
|
||
final String command = 'bash-completion'; | ||
|
||
Future<CliResult> run(ArgResults parsedArgs, {bool color: true}) async { | ||
// This is kind of a hack to suppress output coloring, which messes us up since | ||
// we're outputting shell code (the control sequences are syntax errors). | ||
reporter.color = false; | ||
|
||
BashCompletionTask task = bashCompletion(); | ||
await task.done; | ||
if (task.successful) { | ||
return new CliResult.success(task.completionScript); | ||
} else { | ||
return new CliResult.fail('No completion script found.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2015 Workiva Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import 'package:dart_dev/src/tasks/config.dart'; | ||
|
||
class BashCompletionConfig extends TaskConfig {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env sh | ||
|
||
set -e | ||
|
||
# We only support completions when the command is run through | ||
# the `ddev` alias detailed in the README. | ||
|
||
pub run completion:shell_completion_generator ddev> lib/bash-completion.sh |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So does this just try add support for parsing incomplete args? Like if someone were to accidentally run
ddev form
- it would runddev format
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't read through the full source, but it seems like it basically just adds a new command that provides completions. The completion script is then almost entirely generic in that it just runs a special version of ddev itself to get the completions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok I see 👍