/ src / pkgcli.h
pkgcli.h
  1  /*-
  2   * Copyright (c) 2011-2024 Baptiste Daroussin <bapt@FreeBSD.org>
  3   * Copyright (c) 2013 Matthew Seaman <matthew@FreeBSD.org>
  4   *
  5   * SPDX-License-Identifier: BSD-2-Clause
  6   */
  7  
  8  #ifndef _PKGCLI_H
  9  #define _PKGCLI_H
 10  
 11  #include <search.h>
 12  #include <stdbool.h>
 13  #include <stdint.h>
 14  #include <string.h>
 15  #include <xstring.h>
 16  #include <bsd_compat.h>
 17  #include <pkg/vec.h>
 18  
 19  #define pkg_warnx(fmt, ...) pkg_fprintf(stderr, "%S: " fmt, getprogname(), __VA_ARGS__, -1)
 20  #define ll_foreach(head, el) for (el=head; el != NULL; el = (el)->next)
 21  
 22  extern bool quiet;
 23  extern bool newpkgversion;
 24  extern int nbtodl;
 25  
 26  /* pkg add */
 27  int exec_add(int, char **);
 28  void usage_add(void);
 29  
 30  /* pkg alias */
 31  int exec_alias(int, char **);
 32  void usage_alias(void);
 33  
 34  /* pkg annotate */
 35  int exec_annotate(int, char **);
 36  void usage_annotate(void);
 37  
 38  /* pkg audit */
 39  int exec_audit(int, char **);
 40  void usage_audit(void);
 41  
 42  /* pkg autoremove */
 43  int exec_autoremove(int, char **);
 44  void usage_autoremove(void);
 45  
 46  /* pkg check */
 47  int exec_check(int, char **);
 48  void usage_check(void);
 49  
 50  /* pkg clean */
 51  int exec_clean(int, char **);
 52  void usage_clean(void);
 53  
 54  /* pkg create */
 55  int exec_create(int, char **);
 56  void usage_create(void);
 57  
 58  /* pkg delete */
 59  void usage_delete(void);
 60  int exec_delete(int, char **);
 61  
 62  /* pkg info */
 63  
 64  int exec_info(int, char **);
 65  void usage_info(void);
 66  
 67  /* pkg install */
 68  int exec_install(int, char **);
 69  void usage_install(void);
 70  
 71  /* pkg plugins */
 72  int exec_plugins(int, char **);
 73  void usage_plugins(void);
 74  
 75  /* pkg key */
 76  int exec_key(int, char **);
 77  void usage_key(void);
 78  
 79  /* pkg lock */
 80  int exec_lock(int, char **);
 81  int exec_unlock(int, char **);
 82  void usage_lock(void);
 83  
 84  /* pkg query */
 85  int exec_query(int, char **);
 86  void usage_query(void);
 87  
 88  /* pkg register */
 89  void usage_register(void);
 90  int exec_register(int argc, char **argv);
 91  
 92  /* pkg repo */
 93  int exec_repo(int, char **);
 94  void usage_repo(void);
 95  
 96  /* pkg repo */
 97  int exec_repositories(int, char **);
 98  void usage_repositories(void);
 99  
100  /* pkg rquery */
101  int exec_rquery(int, char **);
102  void usage_rquery(void);
103  
104  /* pkg set */
105  int exec_set(int, char **);
106  void usage_set(void);
107  
108  /* pkg search */
109  int exec_search(int, char **);
110  void usage_search(void);
111  
112  /* pkg shlib */
113  int exec_shlib(int, char **);
114  void usage_shlib(void);
115  char *sanitize(char *, const char *, size_t);
116  
117  /* pkg stats */
118  #define STATS_LOCAL (1<<0)
119  #define STATS_REMOTE (1<<1)
120  
121  int exec_stats(int, char **);
122  void usage_stats(void);
123  
124  /* pkg triggers */
125  int exec_triggers(int, char **);
126  void usage_triggers(void);
127  
128  /* pkg unregister */
129  void usage_unregister(void);
130  int exec_unregister(int, char **);
131  
132  /* pkg update */
133  int exec_update(int, char **);
134  void usage_update(void);
135  int pkgcli_update(bool, bool, c_charv_t *);
136  
137  /* pkg updating */
138  int exec_updating(int, char **);
139  void usage_updating(void);
140  
141  /* pkg upgrade */
142  int exec_upgrade(int, char **);
143  void usage_upgrade(void);
144  
145  /* pkg fetch */
146  int exec_fetch(int, char **);
147  void usage_fetch(void);
148  
149  /* pkg shell */
150  int exec_shell(int, char **);
151  void usage_shell(void);
152  
153  /* pkg version */
154  #define VERSION_SOURCE_INDEX	(1U<<0)
155  #define VERSION_ORIGIN		(1U<<1)
156  #define VERSION_QUIET		(1U<<2)
157  #define VERSION_VERBOSE		(1U<<3)
158  #define VERSION_STATUS		(1U<<4)
159  #define VERSION_NOSTATUS	(1U<<5)
160  #define VERSION_WITHORIGIN	(1U<<7)
161  #define VERSION_TESTVERSION	(1U<<8)
162  #define VERSION_TESTPATTERN	(1U<<9)
163  #define VERSION_SOURCE_PORTS	(1U<<10)
164  #define VERSION_SOURCE_REMOTE	(1U<<11)
165  #define VERSION_INDEX_FILE_NAME	(1U<<12)
166  #define VERSION_WITHNAME	(1U<<13)
167  
168  #define VERSION_SOURCES	(VERSION_SOURCE_PORTS | \
169  			 VERSION_SOURCE_INDEX | \
170  			 VERSION_SOURCE_REMOTE)
171  
172  int exec_version(int, char **);
173  void usage_version(void);
174  
175  /* pkg which */
176  int exec_which(int, char **);
177  void usage_which(void);
178  
179  /* pkg ssh */
180  int exec_ssh(int, char **);
181  void usage_ssh(void);
182  
183  /* pkg config */
184  int exec_config(int, char **);
185  void usage_config(void);
186  
187  /* utils */
188  
189  /* These are the fields of the Full output, in order */
190  #define INFO_NAME		(1LL<<0)
191  #define INFO_VERSION		(1LL<<1)
192  #define INFO_INSTALLED		(1LL<<2)
193  #define INFO_ORIGIN		(1LL<<3)
194  #define INFO_ARCH		(1LL<<4)
195  #define INFO_PREFIX		(1LL<<5)
196  #define INFO_REPOSITORY		(1LL<<6)
197  #define INFO_CATEGORIES		(1LL<<7)
198  #define INFO_LICENSES		(1LL<<8)
199  #define INFO_MAINTAINER		(1LL<<9)
200  #define INFO_WWW		(1LL<<10)
201  #define INFO_COMMENT		(1LL<<11)
202  #define INFO_OPTIONS		(1LL<<12)
203  #define INFO_SHLIBS_REQUIRED	(1LL<<13)
204  #define INFO_SHLIBS_PROVIDED	(1LL<<14)
205  #define INFO_ANNOTATIONS	(1LL<<15)
206  #define INFO_FLATSIZE		(1LL<<16)
207  #define INFO_PKGSIZE		(1LL<<17)
208  #define INFO_DESCR		(1LL<<18)
209  #define INFO_PROVIDED		(1LL<<19)
210  #define INFO_REQUIRED		(1LL<<20)
211  
212  /* Other fields not part of the Full output */
213  #define INFO_MESSAGE		(1LL<<21)
214  #define INFO_DEPS		(1LL<<22)
215  #define INFO_RDEPS		(1LL<<23)
216  #define INFO_FILES		(1LL<<24)
217  #define INFO_DIRS		(1LL<<25)
218  #define INFO_USERS		(1LL<<26)
219  #define INFO_GROUPS		(1LL<<27)
220  #define INFO_REPOURL		(1LL<<28)
221  #define INFO_LOCKED		(1LL<<29)
222  #define INFO_OPTION_DEFAULTS    (1LL<<30)
223  #define INFO_OPTION_DESCRIPTIONS (1LL<<31)
224  
225  #define INFO_LASTFIELD	INFO_LOCKED
226  #define INFO_ALL	(((INFO_LASTFIELD) << 1) - 1)
227  
228  /* Identifying tags */
229  #define INFO_TAG_NAME		(1LL<<32)
230  #define INFO_TAG_ORIGIN		(1LL<<33)
231  #define INFO_TAG_NAMEVER	(1LL<<34)
232  
233  /* Output YAML format */
234  #define INFO_RAW		(1LL<<35)
235  #define INFO_RAW_YAML		(1LL<<36)
236  #define INFO_RAW_JSON		(1LL<<37)
237  #define INFO_RAW_JSON_COMPACT	(1LL<<38)
238  #define INFO_RAW_UCL		(1LL<<39)
239  
240  /* Everything in the 'full' package output */
241  #define INFO_FULL	(INFO_NAME|INFO_VERSION|INFO_INSTALLED|INFO_ORIGIN| \
242  			 INFO_ARCH|INFO_PREFIX|INFO_REPOSITORY|		 \
243  			 INFO_CATEGORIES|INFO_LICENSES|INFO_MAINTAINER|	 \
244  			 INFO_WWW|INFO_COMMENT|INFO_OPTIONS|		 \
245  			 INFO_SHLIBS_REQUIRED|INFO_SHLIBS_PROVIDED|	 \
246  			 INFO_ANNOTATIONS|INFO_FLATSIZE|INFO_PKGSIZE|	 \
247  			 INFO_DESCR|INFO_PROVIDED|INFO_REQUIRED)
248  
249  /* Everything that can take more than one line to print */
250  #define INFO_MULTILINE	(INFO_OPTIONS|INFO_SHLIBS_REQUIRED|	       \
251  			 INFO_SHLIBS_PROVIDED|INFO_ANNOTATIONS|	       \
252  			 INFO_DESCR|INFO_MESSAGE|INFO_DEPS|INFO_RDEPS| \
253  			 INFO_FILES|INFO_DIRS)
254  
255  bool query_yesno(bool deft, const char *msg, ...);
256  int query_select(const char *msg, const char **opts, int ncnt, int deft);
257  bool query_tty_yesno(bool deft, const char *msg, ...);
258  int info_flags(uint64_t opt, bool remote);
259  void print_info(struct pkgdb *db, struct pkg * const pkg, uint64_t opt);
260  int print_jobs_summary(struct pkg_jobs *j, const char *msg, ...);
261  
262  void job_status_begin(xstring *);
263  void job_status_end(xstring *);
264  
265  int event_callback(void *data, struct pkg_event *ev);
266  int print_pkg(struct pkg *p, void *ctx);
267  void print_repository(struct pkg_repo *repo, bool pad);
268  void pkgcli_autoremove(struct pkgdb *db, bool flag);
269  void progressbar_start(const char *pmsg);
270  void progressbar_tick(int64_t current, int64_t total);
271  void progressbar_stop(void);
272  
273  extern xstring *messages;
274  
275  
276  /* pkg-query / pkg-rquery */
277  struct query_flags {
278  	const char flag;
279  	const char *options;
280  	const unsigned multiline;
281  	const int dbflags;
282  };
283  
284  void print_query(struct pkg *pkg, char *qstr, char multiline);
285  int format_sql_condition(const char *str, xstring *sqlcond,
286  			 bool for_remote);
287  int analyse_query_string(char *qstr, struct query_flags *q_flags,
288  			 const unsigned int q_flags_len, int *flags,
289  			 char *multiline);
290  int password_cb(char *buf, int size, int rwflag, void *key);
291  
292  extern int default_yes;
293  extern int yes;
294  extern int dry_run;
295  extern bool auto_update;
296  extern int force;
297  extern bool quiet;
298  extern bool newpkgversion;
299  void set_globals(void);
300  
301  #endif