|
| 1 | +// Copyright (c) 2020, the Dart project authors and OnePub IP Pty Ltd |
| 2 | +// |
| 3 | +// Please see the AUTHORS file |
| 4 | +// for details. All rights reserved. Use of this source code is governed by a |
| 5 | +// BSD-style license that can be found in the LICENSE file. |
| 6 | + |
| 7 | +import 'package:dcli/dcli.dart'; |
| 8 | +import 'package:onepub/src/pub/command/add.dart'; |
| 9 | + |
| 10 | +import '../../exceptions.dart'; |
| 11 | +import '../../onepub_settings.dart'; |
| 12 | +import '../../util/one_pub_token_store.dart'; |
| 13 | + |
| 14 | +/// Handles the `add` pub command. Adds a dependency to `pubspec.yaml` and gets |
| 15 | +/// the package. The user may pass in a git constraint, host url, or path as |
| 16 | +/// requirements. If no such options are passed in, this command will do a |
| 17 | +/// resolution to find the latest version of the package that is compatible with |
| 18 | +/// the other dependencies in `pubspec.yaml`, and then enter that as the lower |
| 19 | +/// bound in a ^x.y.z constraint. |
| 20 | +/// |
| 21 | +/// Currently supports only adding one dependency at a time. |
| 22 | +class AddPrivateCommand extends AddCommand { |
| 23 | + @override |
| 24 | + String get name => 'add'; |
| 25 | + @override |
| 26 | + String get description => blue('Add private dependencies to pubspec.yaml.'); |
| 27 | + @override |
| 28 | + String get argumentsDescription => |
| 29 | + '<package>[:<constraint>] [<package2>[:<constraint2>]...] [options]'; |
| 30 | + @override |
| 31 | + String get docUrl => 'https://dart.dev/tools/pub/cmd/pub-add'; |
| 32 | + |
| 33 | + @override |
| 34 | + String? get hostUrl { |
| 35 | + final url = OnePubSettings().onepubHostedUrl().toString(); |
| 36 | + print(url); |
| 37 | + return url; |
| 38 | + } |
| 39 | + |
| 40 | + @override |
| 41 | + bool get isOffline => false; |
| 42 | + |
| 43 | + bool get hasHostOptions => hostUrl != null; |
| 44 | + |
| 45 | + AddPrivateCommand() : super(includeSourceOptions: false); |
| 46 | + |
| 47 | + @override |
| 48 | + Future<void> runProtected() async { |
| 49 | + OnePubSettings.load(); |
| 50 | + |
| 51 | + if (!OnePubTokenStore().isLoggedIn) { |
| 52 | + throw ExitException( |
| 53 | + exitCode: 1, message: "You must run 'onepub login' first."); |
| 54 | + } |
| 55 | + await super.runProtected(); |
| 56 | + } |
| 57 | +} |
0 commit comments