# - add a test to propose iSCSI and Trusted Extensions completions only when such system is present;
# - Illumos man pages suggests that it does not support nbmand nor atime mount option, so these properties should be proposed only when available
# - generally, propose properties only when the current OS and ZFS versions support them;
# - for the promote command, propose only eligible filesystems;
# - for the rollback command, propose only the most recent snapshot for each dataset, as it will not accept an intermediary snapshot;
# - for the release command, complete with existing tags;
# - for the diff command, complete the destination dataset of the diff;
# - for the program command, complete the script to be executed
# - for commands accepting several arguments of different types, propose arguments in the right order: for get, once the ZFS parameters have been given, only propose datasets
# The remaining code of the function is almost a duplicate of __fish_complete_zfs_rw_properties and __fish_complete_zfs_ro_properties, but almost only, hence the duplication
complete-c zfs -x-n'__fish_zfs_using_command create'-s o -d'Dataset property'-a'(__fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties)'
end
# create completions for volumes; as -V is necessary to zfs to recognize a volume creation request, we use it as a condition to propose volume creation completions
# If -V is typed after -s or -b, zfs should accept it, but fish won't propose -s or -b, but, as these options are for volumes only, it seems reasonable to expect the user to ask for a volume, with -V, before giving its characteristics with -s or -b
complete-c zfs -x-n'__fish_zfs_using_command create'-s V -d'Volume size'
complete-c zfs -f-n'__fish_zfs_using_command create; and __fish_contains_opt -s V'-s s -d'Create a sparse volume'
# destroy completions; as the dataset is the last item, we can't know yet if it's a snapshot, a bookmark or something else, so we can't separate snapshot-specific options from others
complete-c zfs -f-n'__fish_zfs_using_command destroy'-s r -d'Recursively destroy children'
complete-c zfs -f-n'__fish_zfs_using_command destroy'-s R -d'Recursively destroy all dependents'
complete-c zfs -f-n'__fish_zfs_using_command destroy'-s f -d'Force unmounting'
complete-c zfs -f-n'__fish_zfs_using_command destroy'-s n -d'Dry run'
complete-c zfs -f-n'__fish_zfs_using_command destroy'-s p -d'Print machine-parsable verbose information'
complete-c zfs -f-n'__fish_zfs_using_command destroy'-s v -d'Verbose mode'
complete-c zfs -f-n'__fish_zfs_using_command destroy'-s d -d'Defer snapshot deletion'
complete-c zfs -x-n'__fish_zfs_using_command destroy'-d'Dataset to destroy'-a'(__fish_print_zfs_filesystems; __fish_print_zfs_volumes; __fish_print_zfs_snapshots; __fish_print_zfs_bookmarks)'
# snapshot completions
complete-c zfs -f-n'__fish_zfs_using_command snapshot; or __fish_zfs_using_command snap'-s r -d'Recursively snapshot children'
complete-c zfs -x-n'__fish_zfs_using_command snapshot; or __fish_zfs_using_command snap'-s o -d'Snapshot property'-a'(__fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties)'
end
complete-c zfs -x-n'__fish_zfs_using_command snapshot; or __fish_zfs_using_command snap'-d'Dataset to snapshot'-a'(__fish_print_zfs_filesystems; __fish_print_zfs_volumes)'
# rollback completions
complete-c zfs -f-n'__fish_zfs_using_command rollback'-s r -d'Destroy later snapshot and bookmarks'
complete-c zfs -f-n'__fish_zfs_using_command rollback'-s R -d'Recursively destroy later snapshot, bookmarks and clones'
complete-c zfs -f-n'__fish_zfs_using_command rollback; and __fish_contains_opt -s R'-s f -d'Force unmounting of clones'
complete-c zfs -x-n'__fish_zfs_using_command promote'-d'Clone to promote'-a'(__fish_print_zfs_filesystems)'
# rename completions; as the dataset is the last item, we can't know yet if it's a snapshot or not, we can't separate snapshot-specific option from others
complete-c zfs -f-n'__fish_zfs_using_command rename'-s p -d'Create all needed non-existing parent datasets'
complete-c zfs -f-n'__fish_zfs_using_command rename'-s r -d'Recursively rename children snapshots'
complete-c zfs -x-n'__fish_zfs_using_command list; and __fish_not_contain_opt -s S'-s s -d'Property to use for sorting output by ascending order'-a'(__fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties; __fish_complete_zfs_ro_properties; echo -e "name\tDataset name")'
complete-c zfs -x-n'__fish_zfs_using_command list; and __fish_not_contain_opt -s s'-s S -d'Property to use for sorting output by descending order'-a'(__fish_complete_zfs_rw_properties; __fish_complete_zfs_write_once_properties; __fish_complete_zfs_ro_properties; echo -e "name\tDataset name")'
complete-c zfs -x-n'__fish_zfs_using_command inherit'-d'Dataset whose properties are to be inherited'-a'(__fish_print_zfs_filesystems; __fish_print_zfs_volumes; __fish_print_zfs_snapshots)'
complete-c zfs -x-n'__fish_zfs_using_command userspace; or __fish_zfs_using_command groupspace'-s o -d'Field to display'-a'(__fish_append , (__fish_zfs_list_space_fields))'
complete-c zfs -x-n'__fish_zfs_using_command userspace; or __fish_zfs_using_command groupspace; and __fish_not_contain_opt -s S'-s s -d'Property to use for sorting output by ascending order'-a __fish_zfs_list_space_fields
complete-c zfs -x-n'__fish_zfs_using_command userspace; or __fish_zfs_using_command groupspace; and __fish_not_contain_opt -s s'-s S -d'Property to use for sorting output by descending order'-a __fish_zfs_list_space_fields
complete-c zfs -x-n'__fish_zfs_using_command userspace; or __fish_zfs_using_command groupspace'-d'Dataset whose space usage to get'-a'(__fish_print_zfs_filesystems; __fish_print_zfs_snapshots)'
complete-c zfs -x-n'__fish_zfs_using_command mount'-s o -d'Temporary mount point property'-a'(__fish_append , (__fish_complete_zfs_mountpoint_properties))'
complete-c zfs -f-n'__fish_zfs_using_command mount'-s v -d'Report progress'
complete-c zfs -f-n'__fish_zfs_using_command mount'-s a -d'Mount all available ZFS filesystems'
ifcontains-- $OS Linux SunOS
complete-c zfs -f-n'__fish_zfs_using_command mount'-s O -d'Overlay mount'
end
complete-c zfs -x-n'__fish_zfs_using_command mount; and __fish_not_contain_opt -s a'-d'Filesystem to mount'-a'(__fish_print_zfs_filesystems)'
# unmount completions
complete-c zfs -f-n'__fish_zfs_using_command unmount; or __fish_zfs_using_command umount'-s f -d'Force unmounting if needed'
complete-c zfs -f-n'__fish_zfs_using_command unmount; or __fish_zfs_using_command umount'-s a -d'Unmount all available ZFS filesystems'
complete-c zfs -x-n'__fish_zfs_using_command unmount; or __fish_zfs_using_command umount; and __fish_not_contain_opt -s a'-d'Filesystem to unmount'-a'(__fish_print_zfs_filesystems; __fish_print_mounted)'
# share completions
complete-c zfs -f-n'__fish_zfs_using_command share'-s a -d'Share all eligible ZFS filesystems'
complete-c zfs -x-n'__fish_zfs_using_command share; and __fish_not_contain_opt -s a'-d'Filesystem to share'-a'(__fish_print_zfs_filesystems)'
# unshare completions
complete-c zfs -f-n'__fish_zfs_using_command unshare'-s a -d'Unshare all shared ZFS filesystems'
complete-c zfs -x-n'__fish_zfs_using_command unshare; and __fish_not_contain_opt -s a'-d'Filesystem to unshare'-a'(__fish_print_zfs_filesystems; __fish_print_mounted)'
# bookmark completions
if __fish_is_zfs_feature_enabled 'feature@bookmarks'
complete-c zfs -x-n'__fish_zfs_using_command bookmark'-d'Snapshot to bookmark'-a'(__fish_print_zfs_snapshots)'
complete-c zfs -x-n'__fish_zfs_using_command send'-s i -d'Generate incremental stream from snapshot'-a'(__fish_print_zfs_snapshots --force; __fish_print_zfs_bookmarks)'
complete-c zfs -x-n'__fish_zfs_using_command send'-s I -d'Generate incremental stream from snapshot, even with intermediary snapshots'-a'(__fish_print_zfs_snapshots --force)'
complete-c zfs -f-n'__fish_zfs_using_command send'-s R -l replicate -d'Include children in replication stream'
complete-c zfs -f-n'__fish_zfs_using_command send'-s D -l dedup -d'Generate a deduplicated stream'
complete-c zfs -f-n'__fish_zfs_using_command send; and __fish_is_zfs_feature_enabled "feature@large_blocks"'-s L -l large-block -d'Allow the presence of larger blocks than 128kiB'
complete-c zfs -f-n'__fish_zfs_using_command send; and __fish_is_zfs_feature_enabled "feature@embedded_data"'-s e -l embed -d'Generate a more compact stream by using WRITE_EMBEDDED records'
complete-c zfs -f-n'__fish_zfs_using_command send'-s P -l parsable -d'Print verbose information about the stream in a machine-parsable format'
complete-c zfs -f-n'__fish_zfs_using_command send'-s c -l compressed -d'Generate compressed stream'
complete-c zfs -f-n'__fish_zfs_using_command send'-s n -l dryrun -d'Dry run'
complete-c zfs -f-n'__fish_zfs_using_command send; and __fish_not_contain_opt -s R'-s p -l props -d'Include dataset properties'
complete-c zfs -f-n'__fish_zfs_using_command send'-s v -l verbose -d'Print verbose information about the stream'
else
complete-c zfs -f-n'__fish_zfs_using_command send'-s R -d'Include children in replication stream'
complete-c zfs -f-n'__fish_zfs_using_command send'-s D -d'Generate a deduplicated stream'
complete-c zfs -f-n'__fish_zfs_using_command send; and __fish_is_zfs_feature_enabled "feature@large_blocks"'-s L -d'Allow the presence of larger blocks than 128kiB'
complete-c zfs -f-n'__fish_zfs_using_command send; and __fish_is_zfs_feature_enabled "feature@embedded_data"'-s e -d'Generate a more compact stream by using WRITE_EMBEDDED records'
complete-c zfs -f-n'__fish_zfs_using_command send'-s P -d'Print verbose information about the stream in a machine-parsable format'
complete-c zfs -f-n'__fish_zfs_using_command send'-s n -d'Dry run'
complete-c zfs -f-n'__fish_zfs_using_command send; and __fish_not_contain_opt -s R'-s p -d'Include dataset properties'
complete-c zfs -f-n'__fish_zfs_using_command send'-s v -d'Print verbose information about the stream'
complete-c zfs -f-n'__fish_zfs_using_command receive; or __fish_zfs_using_command recv'-s v -d'Print verbose information about the stream and the time spent processing it'
complete-c zfs -f-n'__fish_zfs_using_command receive; or __fish_zfs_using_command recv'-s n -d'Dry run: do not actually receive the stream'
complete-c zfs -f-n'__fish_zfs_using_command receive; or __fish_zfs_using_command recv'-s F -d'Force rollback to the most recent snapshot'
complete-c zfs -f-n'__fish_zfs_using_command receive; or __fish_zfs_using_command recv'-s u -d'Unmount the target filesystem'
complete-c zfs -f-n'__fish_zfs_using_command receive; or __fish_zfs_using_command recv; and __fish_not_contain_opt -s e'-s d -d'Discard the first element of the path of the sent snapshot'
complete-c zfs -f-n'__fish_zfs_using_command receive; or __fish_zfs_using_command recv; and __fish_not_contain_opt -s d'-s e -d'Discard all but the last element of the path of the sent snapshot'
complete-c zfs -x-n'__fish_zfs_using_command receive; or __fish_zfs_using_command recv'-s o -d'Force the stream to be received as a clone of the given snapshot'-a origin
if __fish_is_zfs_feature_enabled "feature@extensible_dataset"
complete-c zfs -f-n'__fish_zfs_using_command receive; or __fish_zfs_using_command recv'-s s -d'On transfer interruption, store a receive_resume_token for resumption'
complete-c zfs -x-n'__fish_zfs_using_command receive; or __fish_zfs_using_command recv'-d'Dataset to receive'-a'(__fish_print_zfs_filesystems; __fish_print_zfs_volumes;)'
complete-c zfs -x-n'__fish_zfs_using_command allow; and __fish_not_contain_opt -s l -s d -s e -s g -s u -s s'-s c -d'Delegate permissions only to the creator of later descendent datasets'-a'(__fish_append , (__fish_zfs_list_permissions))'
complete-c zfs -x-n'__fish_zfs_using_command allow; and __fish_not_contain_opt -s l -s d -s e -s g -s u -s c'-s s -d'Create a permission set or add permissions to an existing one'
complete-c zfs -x-n'__fish_zfs_using_command allow'-d'Dataset on which delegation is to be applied'-a'(__fish_print_zfs_filesystems; __fish_print_zfs_volumes)'
# unallow completions
complete-c zfs -f-n'__fish_zfs_using_command unallow; and __fish_not_contain_opt -s d'-s l -d'Remove permissions only on the specified dataset'
complete-c zfs -f-n'__fish_zfs_using_command unallow; and __fish_not_contain_opt -s l'-s d -d'Remove permissions only on the descendents dataset'
complete-c zfs -x-n'__fish_zfs_using_command unallow; and __fish_not_contain_opt -s l -s d -s e -s g -s u -s s'-s c -d'Remove permissions only on later created descendent datasets'-a'(__fish_append , (__fish_zfs_list_permissions))'
complete-c zfs -x-n'__fish_zfs_using_command unallow; and __fish_not_contain_opt -s l -s d -s e -s g -s u -s c'-s s -d'Remove a permission set or remove permissions from an existing one'
complete-c zfs -x-n'__fish_zfs_using_command unallow'-d'Dataset on which delegation is to be removed'-a'(__fish_print_zfs_filesystems; __fish_print_zfs_volumes)'
# hold completions
complete-c zfs -f-n'__fish_zfs_using_command hold'-s r -d'Apply hold recursively'
complete-c zfs -x-n'__fish_zfs_using_command hold'-d'Snapshot on which hold is to be applied'-a'(__fish_print_zfs_snapshots)'
# holds completions
complete-c zfs -f-n'__fish_zfs_using_command holds'-s r -d'List holds recursively'